Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

neonoFailed Tests

pekora

give me two candy!

pekora(a,b)=> 'candy';
add(a)=> 'candy';
Code
Diff
  • a(){}
  • 1
    void main() {
    
    2
      print('Hello Dart!');
    
    3
    }
    
    1+
    a(){}
    

:v

Code
Diff
  • addition(a,b) => a != 123 ? 2 : 444;
  • 1
    int addition(int a, int b) => a + b;
    
    1+
    addition(a,b) => a != 123 ? 2 : 444;
    

I would love to see a generator which accepts [(Gen s, Int)] and uses a set of generators, generates n inputs from each of them, shuffles them, and uses the inputs to feed test cases.

For example, for "Is a number prime?" kata, I'd like to have a composite generator built like compositeGen([(genPrimes, 100), (genOddComposites, 100), (genNegativePrime, 10), (genSquareOfAPrime, 20)]) or something like this, and it would run test cases over 230 shuffled inputs.

Bonus points if such generator were able to generate not only Int, but also (Int, Bool) (input + expected answer) or even (Int, Bool, String) (input, expected answer, and assertion message).


The one thing I can't fix is that if it fails, it's always after 1 test. Because that's what it sees.

module Example (isPrime) where

isPrime :: Int -> Bool
isPrime = odd
Code
Diff
  • import java.util.*;
    interface HighLow {
      static int[] printLargestAndSmallest(int[] nums) {
        Arrays.sort(nums);
        return new int[] {nums[0], nums[nums.length-1]};
      }
    }
  • 1+
    import java.util.*;
    
    11
    interface HighLow {
    
    22
      static int[] printLargestAndSmallest(int[] nums) {
    
    3
        int min = nums[0], max = nums[0];
    
    4
        for (int n : nums) {
    
    5
          if (n < min) min = n;
    
    6
          if (n > max) max = n;
    
    7
        }
    
    8
        return new int[] {min, max};
    
    4+
        Arrays.sort(nums);
    
    5+
        return new int[] {nums[0], nums[nums.length-1]};
    
    99
      }
    
    1010
    }
    

Optimization: you don't need to go all the way to n.

Code
Diff
  • export const checkIsPrimeNumber = (n: number) => 
    {
      if (!Number.isInteger(n)) return false;
      for (var i = 2; i <= Math.min(n, Math.sqrt(n)); i++) {
        if (n % i === 0) return false;
      }
      return n > 1;
    };
  • 11
    export const checkIsPrimeNumber = (n: number) => 
    
    22
    {
    
    33
      if (!Number.isInteger(n)) return false;
    
    4
      for (var i = 2; i < n; i++) {
    
    4+
      for (var i = 2; i <= Math.min(n, Math.sqrt(n)); i++) {
    
    55
        if (n % i === 0) return false;
    
    66
      }
    
    77
      return n > 1;
    
    88
    };
    

Bitwise operations usually work faster than arithmetic.

Code
Diff
  • power_of_two = lambda n: not n&1
  • 1
    power_of_two = lambda n: n == (n>>1)<<1
    
    1+
    power_of_two = lambda n: not n&1
    

Recent Moves: