Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

Kumite (ko͞omiˌtā) is the practice of taking techniques learned from Kata and applying them through the act of freestyle sparring.

You can create a new kumite by providing some initial code and optionally some test cases. From there other warriors can spar with you, by enhancing, refactoring and translating your code. There is no limit to how many warriors you can spar with.

A great use for kumite is to begin an idea for a kata as one. You can collaborate with other code warriors until you have it right, then you can convert it to a kata.

Ad
Ad
Code
Diff
  • import static java.util.function.Predicate.not;
    import static java.util.regex.Pattern.compile;
    
    interface StringCalculator {
      static int add(String numbers) {
        return compile("\\D")
            .splitAsStream(numbers)
            .filter(not(String::isEmpty))
            .mapToInt(Integer::parseInt)
            .sum();
      }
    }
    • import java.util.Arrays;
    • import static java.util.function.Predicate.not;
    • import static java.util.regex.Pattern.compile;
    • interface StringCalculator {
    • static int add(String numbers) {
    • return Arrays.stream(numbers.split("\\D"))
    • .filter(str -> str.length() > 0)
    • .mapToInt(Integer::parseInt)
    • .sum();
    • return compile("\\D")
    • .splitAsStream(numbers)
    • .filter(not(String::isEmpty))
    • .mapToInt(Integer::parseInt)
    • .sum();
    • }
    • }
Code
Diff
  • import static java.util.stream.IntStream.rangeClosed;
    import java.util.List;
    
    interface FizzBuzz {
      static List<String> evaluate(int input) {
        return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList();
      }
      
      private static String determineFizzbuzz(int n) {
        String ans = "";
        if (n % 3 == 0)
          ans += "Fizz";
        if (n % 5 == 0)
          ans += "Buzz";
        return ans.length() > 0 ? ans : Integer.toString(n);
      }
    }
    • import static java.util.stream.IntStream.rangeClosed;
    • import java.util.List;
    • interface FizzBuzz {
    • static List<String> evaluate(int input) {
    • return rangeClosed(1, input).mapToObj(i -> i % 15 == 0 ? "FizzBuzz" :
    • i % 5 == 0 ? "Buzz" : i % 3 == 0 ? "Fizz" : "" + i).toList();
    • return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList();
    • }
    • private static String determineFizzbuzz(int n) {
    • String ans = "";
    • if (n % 3 == 0)
    • ans += "Fizz";
    • if (n % 5 == 0)
    • ans += "Buzz";
    • return ans.length() > 0 ? ans : Integer.toString(n);
    • }
    • }

Shortified ;)

Code
Diff
  • import static com.google.common.primitives.Ints.*;
    import static org.apache.commons.lang3.ArrayUtils.isEmpty;
    
    interface HighLow {
      static int[] findLargestAndSmallest(int[] nums) {
        return isEmpty(nums) ? null : new int[]{min(nums), max(nums)};
      }
    }
    • import static java.util.stream.IntStream.of;
    • import static com.google.common.primitives.Ints.*;
    • import static org.apache.commons.lang3.ArrayUtils.isEmpty;
    • interface HighLow {
    • static int[] findLargestAndSmallest(int[] nums) {
    • return (nums == null || nums.length == 0) ? null : new int[] {of(nums).summaryStatistics().getMin(), of(nums).summaryStatistics().getMax()};
    • }
    • }
    • static int[] findLargestAndSmallest(int[] nums) {
    • return isEmpty(nums) ? null : new int[]{min(nums), max(nums)};
    • }
    • }
Algorithms
Mathematics
Code
Diff
  • function prime_checker(e){return!(e<=1)&&
      [...Array(Math.ceil(Math.sqrt(e))).keys()].slice(2).every(r=>e%r)}
    • function prime_checker(n) {
    • return n <= 1 ? false : [...Array(Math.ceil(Math.sqrt(n))).keys()].slice(2).every((v) => n % v);
    • };
    • function prime_checker(e){return!(e<=1)&&
    • [...Array(Math.ceil(Math.sqrt(e))).keys()].slice(2).every(r=>e%r)}
Code
Diff
  • using System;
    
    public class LeapYears
    {
      // A leap year is any year that's divisible by 4 EXCEPT for years that're both divisible by 100 and not divisible by 400.
      public static bool IsLeapYear(int year) => year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
    }
    • using System;
    • public class LeapYears
    • {
    • public static bool IsLeapYear(int year)
    • {
    • return year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
    • }
    • // A leap year is any year that's divisible by 4 EXCEPT for years that're both divisible by 100 and not divisible by 400.
    • public static bool IsLeapYear(int year) => year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
    • }