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.

Code
Diff
  • const code = String.raw`
    Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
    True = \ t f . t
    False = \ t f . f
    Succ = \ n s z . s (n s z)
    Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
    Minus = \ m n . n Pred m
    Times = \ m n s . m (n s)
    isZero = \ n . n (\_.False) True
    isNotZero = \ n . n (\_.True) False
    And = \ x y . x y x
    Or = \ x . x x
    GT = \ x y . isNotZero (Minus x y)
    Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
    
    # function isPrime(n) {
    #   const trial = function trial(i) {
    #     return i * i > n || n % i != 0 && trial(i+1) ;
    #   } ;
    #   return n > 1 && trial(2) ;
    # }
    
    isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
                    ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
    `
  • 11
    const code = String.raw`
    
    2
    succ = \ n f x . f (n f x)
    
    3
    pair = \a.\b.\c.c a b
    
    4
    fst = \pair.pair (\a.\_.a)
    
    5
    snd = \pair.pair (\_.\b.b)
    
    6
    plus = \pair.\f.\x.(fst pair) f ((snd pair) f x)
    
    7
    next = \prev.pair (snd prev) (plus prev)
    
    8
    fibonacci = \n. fst (n next (pair (\_.\b.b) (succ (\_.\b.b))))
    
    9
    `
    
    2+
    Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
    
    3+
    True = \ t f . t
    
    4+
    False = \ t f . f
    
    5+
    Succ = \ n s z . s (n s z)
    
    6+
    Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
    
    7+
    Minus = \ m n . n Pred m
    
    8+
    Times = \ m n s . m (n s)
    
    9+
    isZero = \ n . n (\_.False) True
    
    10+
    isNotZero = \ n . n (\_.True) False
    
    11+
    And = \ x y . x y x
    
    12+
    Or = \ x . x x
    
    13+
    GT = \ x y . isNotZero (Minus x y)
    
    14+
    Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
    
    1010
    11
    // Stress testing -- "LetRec", "BinaryScott"
    
    12
    // Testing implementation of a "String" - ie. Arrays and related functions
    
    13
    const stress = String.raw`
    
    14
    # bools
    
    15
    id = \ x . x
    
    16
    true = \ a b . a
    
    17
    false = \ a b . b
    
    18
    not = \ b . b false true
    
    19
    and = \ a b . a b false
    
    20
    or = \ a b . a true b
    
    21
    xor = \ a b . a (b false true) b
    
    16+
    # function isPrime(n) {
    
    17+
    #   const trial = function trial(i) {
    
    18+
    #     return i * i > n || n % i != 0 && trial(i+1) ;
    
    19+
    #   } ;
    
    20+
    #   return n > 1 && trial(2) ;
    
    21+
    # }
    
    2222
    23
    # ints -- z = endbit, f = offbit, t = onbit
    
    24
    zero = \ z _ _ . z
    
    25
    succ = \ n _ f t . n (t zero) t (\ m . f (succ m))
    
    26
    bool = \ n . n false (\ _ . true) (\ _ . true)
    
    27
    pred = \ n z f t . n z (\ m . t (pred m)) (\ m . bool m (f m) z)
    
    28
    odd = \ n . n false false true
    
    29
    even = \ n . not (odd n)
    
    30
    mul2 = \ n _ f _ . f n
    
    31
    addSlow = \ a b . bool b (addSlow (succ a) (pred b)) a
    
    32
    subSlow = \ a b . bool a (bool b (subSlow (pred a) (pred b)) a) (zero)
    
    33
    34
    # arrays as foldr (strings)
    
    23+
    isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
    
    24+
                    ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
    
    3535
    `
    

Recent Moves:

Be careful! You were previously implicitly defining a global fact when you really should not have done that. A lot of these problems can be solved by including that "use strict"; at the start of a function, which is especially important when you're starting out.
Also, factorial of 0 is 1, and factorial of negatives is undefined. It's also nice to have proper indentation to make programs a little easier to read.

Code
Diff
  • function factorial (n) {
      "use strict";
      if (n < 0) {
        return NaN
      }
      let i, fact
      i = fact = 1
      while (i <= n) { 
        fact *= i
        i++
      }
      return fact
    }
  • 11
    function factorial (n) {
    
    2
      if (n <= 0) return 0
    
    3
      
    
    4
      let i = fact = 1
    
    2+
      "use strict";
    
    3+
      if (n < 0) {
    
    4+
        return NaN
    
    5+
      }
    
    6+
      let i, fact
    
    7+
      i = fact = 1
    
    55
      while (i <= n) { 
    
    6
      fact *= i
    
    7
      i++
    
    9+
        fact *= i
    
    10+
        i++
    
    88
      }
    
    99
      return fact
    
    10
      
    
    1111
    }
    

Recent Moves:

Code
Diff
  • addition(a,b)=>a+b;
  • 1
    int addition(int a, int b) => a + b;
    
    1+
    addition(a,b)=>a+b;
    

Recent Moves: