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.

Updates to fromInt and toInt

Probably gives initial compile and runtime efficiency improvements, both in time and space.

I feel clever. :P

Code
Diff
  • const code = String.raw`
    succ = \ n f x . f (n f x)
    pair = \a.\b.\c.c a b
    fst = \pair.pair (\a.\_.a)
    snd = \pair.pair (\_.\b.b)
    plus = \pair.\f.\x.(fst pair) f ((snd pair) f x)
    next = \prev.pair (snd prev) (plus prev)
    fibonacci = \n. fst (n next (pair (\_.\b.b) (succ (\_.\b.b))))
    `
    
    // Stress testing -- "LetRec", "BinaryScott"
    // Testing implementation of a "String" - ie. Arrays and related functions
    const stress = String.raw`
    # bools
    id = \ x . x
    true = \ a b . a
    false = \ a b . b
    not = \ b . b false true
    and = \ a b . a b false
    or = \ a b . a true b
    xor = \ a b . a (b false true) b
    
    # ints -- z = endbit, f = offbit, t = onbit
    zero = \ z _ _ . z
    succ = \ n _ f t . n (t zero) t (\ m . f (succ m))
    bool = \ n . n false (\ _ . true) (\ _ . true)
    pred = \ n z f t . n z (\ m . t (pred m)) (\ m . bool m (f m) z)
    odd = \ n . n false false true
    even = \ n . not (odd n)
    mul2 = \ n _ f _ . f n
    addSlow = \ a b . bool b (addSlow (succ a) (pred b)) a
    subSlow = \ a b . bool a (bool b (subSlow (pred a) (pred b)) a) (zero)
    
    # arrays as foldr (strings)
    `
  • 11
    const code = String.raw`
    
    22
    succ = \ n f x . f (n f x)
    
    33
    pair = \a.\b.\c.c a b
    
    44
    fst = \pair.pair (\a.\_.a)
    
    55
    snd = \pair.pair (\_.\b.b)
    
    66
    plus = \pair.\f.\x.(fst pair) f ((snd pair) f x)
    
    77
    next = \prev.pair (snd prev) (plus prev)
    
    88
    fibonacci = \n. fst (n next (pair (\_.\b.b) (succ (\_.\b.b))))
    
    99
    `
    
    1010
    1111
    // Stress testing -- "LetRec", "BinaryScott"
    
    1212
    // Testing implementation of a "String" - ie. Arrays and related functions
    
    1313
    const stress = String.raw`
    
    1414
    # bools
    
    1515
    id = \ x . x
    
    1616
    true = \ a b . a
    
    1717
    false = \ a b . b
    
    1818
    not = \ b . b false true
    
    1919
    and = \ a b . a b false
    
    2020
    or = \ a b . a true b
    
    2121
    xor = \ a b . a (b false true) b
    
    2222
    2323
    # ints -- z = endbit, f = offbit, t = onbit
    
    2424
    zero = \ z _ _ . z
    
    2525
    succ = \ n _ f t . n (t zero) t (\ m . f (succ m))
    
    2626
    bool = \ n . n false (\ _ . true) (\ _ . true)
    
    2727
    pred = \ n z f t . n z (\ m . t (pred m)) (\ m . bool m (f m) z)
    
    2828
    odd = \ n . n false false true
    
    2929
    even = \ n . not (odd n)
    
    3030
    mul2 = \ n _ f _ . f n
    
    3131
    addSlow = \ a b . bool b (addSlow (succ a) (pred b)) a
    
    3232
    subSlow = \ a b . bool a (bool b (subSlow (pred a) (pred b)) a) (zero)
    
    3333
    3434
    # arrays as foldr (strings)
    
    3535
    `
    

Recent Moves:

Code
Diff
  • bool Or(bool a, bool b) {
        return a+b;
    }
    
    bool And(bool a, bool b) {
        return a*b;
    }
    bool Xor(bool a, bool b) {
        return a!=b;
    }
  • 11
    bool Or(bool a, bool b) {
    
    2
        return *("||" +!+ a +!+ b);
    
    2+
        return a+b;
    
    33
    }
    
    44
    55
    bool And(bool a, bool b) {
    
    6
        return !*("&&" + a + b);
    
    6+
        return a*b;
    
    77
    }
    
    88
    bool Xor(bool a, bool b) {
    
    9
        return !*("^" + a + b - a * b * a - b * a * b);
    
    9+
        return a!=b;
    
    1010
    }
    
Mathematics
Algorithms
Numbers

What's [Z?

Code
Diff
  • public class Kata {
      private static Object[] root = {null,
                                        new Object[][]{null, null, null, null, null, null, null, null, null, null, {new Boolean(true)}},
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        null,
                                        new Object[]{new Boolean(false)}
                                       };
      public static boolean isHappy(long current) {
        Boolean[] result = {false};
        outer:
        for (; ; ) {
          long next = 0;
          Object[] node = root;
          while (current > 0) {
            int remainder = (int) (current % 10);
            current /= 10;
            next += remainder * remainder;
            if (node[remainder] == null) {
              node = (Object[]) (node[remainder] = new Object[remainder == 0 ? 10 : 11]);
              while (current > 0) {
                remainder = (int) (current % 10);
                current /= 10;
                next += remainder * remainder;
                node = (Object[]) (node[remainder] = new Object[remainder == 0 ? 10 : 11]);
              }
              node[10] = result;
              current = next;
              continue outer;
            }
            node = (Object[]) node[remainder];
          }
          if (node[10] != null) {
            return result[0] = (Boolean) ((Object[]) node[10])[0];
          }
          node[10] = result;
          current = next;
        }
      }
    }
    
  • 1
    def is_happy(h: int) -> bool:
    
    2
        """Returns `True` if `h` is happy, `False` otherwise."""
    
    3
        seen = set()
    
    4
        while h > 1 and h not in seen:
    
    5
            seen.add(h)
    
    6
            tot = 0
    
    7
            while h > 0:
    
    8
                tot += pow(h % 10, 2)
    
    9
                h //= 10
    
    10
            h = tot
    
    11
        return h == 1
    
    1+
    public class Kata {
    
    2+
      private static Object[] root = {null,
    
    3+
                                        new Object[][]{null, null, null, null, null, null, null, null, null, null, {new Boolean(true)}},
    
    4+
                                        null,
    
    5+
                                        null,
    
    6+
                                        null,
    
    7+
                                        null,
    
    8+
                                        null,
    
    9+
                                        null,
    
    10+
                                        null,
    
    11+
                                        null,
    
    12+
                                        new Object[]{new Boolean(false)}
    
    13+
                                       };
    
    14+
      public static boolean isHappy(long current) {
    
    15+
        Boolean[] result = {false};
    
    16+
        outer:
    
    17+
        for (; ; ) {
    
    18+
          long next = 0;
    
    19+
          Object[] node = root;
    
    20+
          while (current > 0) {
    
    21+
            int remainder = (int) (current % 10);
    
    22+
            current /= 10;
    
    23+
            next += remainder * remainder;
    
    24+
            if (node[remainder] == null) {
    
    25+
              node = (Object[]) (node[remainder] = new Object[remainder == 0 ? 10 : 11]);
    
    26+
              while (current > 0) {
    
    27+
                remainder = (int) (current % 10);
    
    28+
                current /= 10;
    
    29+
                next += remainder * remainder;
    
    30+
                node = (Object[]) (node[remainder] = new Object[remainder == 0 ? 10 : 11]);
    
    31+
              }
    
    32+
              node[10] = result;
    
    33+
              current = next;
    
    34+
              continue outer;
    
    35+
            }
    
    36+
            node = (Object[]) node[remainder];
    
    37+
          }
    
    38+
          if (node[10] != null) {
    
    39+
            return result[0] = (Boolean) ((Object[]) node[10])[0];
    
    40+
          }
    
    41+
          node[10] = result;
    
    42+
          current = next;
    
    43+
        }
    
    44+
      }
    
    45+
    }
    

Recent Moves: