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
  • def match(pattern):
        def matcher(string):
            return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string))
        return matcher
    • def match(pattern):
    • def matcher(string):
    • return len(pattern) == len(string) and all(a == b if a != '.' else True for a, b in zip(pattern, string))
    • return len(pattern) == len(string) and all(a == '.' or a == b for a, b in zip(pattern, string))
    • return matcher
Code
Diff
  • # A whopping 2 character saving.
    cipher_breaker=lambda s:"".join({c:chr(219-ord(c))," ":c}[c]for c in s)
    • cipher_breaker=lambda s:"".join(c==" "and" "or chr(219-ord(c))for c in s)
    • # A whopping 2 character saving.
    • cipher_breaker=lambda s:"".join({c:chr(219-ord(c))," ":c}[c]for c in s)
Code
Diff
  • # Shorter form of the last version.
    add=lambda s,o:sum(filter(lambda n:not o or~(n+o)&1,map(int,s)))
    • # 1 & 1 is 1, 10 & 1 is 0, we know that the least significant bit for any integer is 1 for odd and 0 for even
    • # so we can just compare the least significant bit of both values to answer the question
    • add=lambda s,o:sum(filter(lambda n: n & 1 == o & 1 if o and o < 3 else n, map(int, s)))
    • # Ever so slightly shorter
    • add=lambda s,o:sum(filter(lambda n: ~(n + o) & 1 if o and o < 3 else n, map(int, s)))
    • # Shorter form of the last version.
    • add=lambda s,o:sum(filter(lambda n:not o or~(n+o)&1,map(int,s)))
Numbers
Data Types
Integers
Algorithms
Logic
Code
Diff
  • #include <stdint.h>
    
    uint_fast8_t number_of_digits(uint64_t n)
    {
      uint_fast8_t digits = 1;
      while(n /= 10) digits++;
      return digits;
    }
    • #include <stdint.h>
    • uint_fast8_t number_of_digits(uint64_t n)
    • {
    • uint_fast8_t digits = 0;
    • for (; n > 0; n /= 10) digits++;
    • uint_fast8_t digits = 1;
    • while(n /= 10) digits++;
    • return digits;
    • }
Code
Diff
  • # this has had some interesting solutions,
    # but i have to create a fork using a built-in
    # it is the law
    
    # if you ever actually need an `add` function
    # as a parameter for something,
    # i recommend you use this method
    # in the interest of uniformity
    
    
    from operator import add
    
    • add = lambda *args : args[0]+args[1]
    • # this has had some interesting solutions,
    • # but i have to create a fork using a built-in
    • # it is the law
    • # if you ever actually need an `add` function
    • # as a parameter for something,
    • # i recommend you use this method
    • # in the interest of uniformity
    • from operator import add
Fundamentals
Loops
Control Flow
Basic Language Features

Took advantage of Python yield. I was expecting it to improve performance, but that does not seem to be the case. I think this is slightly easier to understand though.

Code
Diff
  • class Node():
        def __init__(self, value):
            self.value = value
            self.left = None
            self.right = None
        
        def insert(self, n):
            if n.value < self.value:
                if self.left == None:
                    self.left = n
                else:
                    self.left.insert(n)
            else:
                if self.right == None:
                    self.right = n
                else:
                    self.right.insert(n)
        
        def sorted(self):
            if self.left != None:
                yield from self.left.sorted()
            yield self.value
            if self.right != None:
                yield from self.right.sorted()
    
    def sort_arr(arr):
        tree = Node(arr[0])
        for n in arr[1:]:
            tree.insert(Node(n))
        return list(tree.sorted())
    • class Node():
    • def __init__(self, value):
    • self.value = value
    • self.left = None
    • self.right = None
    • def insert(self, n):
    • if n.value < self.value:
    • if self.left == None:
    • self.left = n
    • else:
    • self.left.insert(n)
    • else:
    • if self.right == None:
    • self.right = n
    • else:
    • self.right.insert(n)
    • def sorted(self):
    • s = []
    • if self.left != None:
    • s = self.left.sorted()
    • s.append(self.value)
    • yield from self.left.sorted()
    • yield self.value
    • if self.right != None:
    • s += self.right.sorted()
    • return s
    • yield from self.right.sorted()
    • def sort_arr(arr):
    • tree = Node(arr[0])
    • for n in arr[1:]:
    • tree.insert(Node(n))
    • return tree.sorted()
    • return list(tree.sorted())
Algorithms
Logic
Arrays
Data Types
Mathematics
Numbers
Code
Diff
  • import java.util.stream.IntStream;
    
    public class ArrayFactorial{
        public static int factorial(int n, int k) {
            return IntStream.rangeClosed(1, Math.min(k, n - k))
                .reduce(1, (r, i) -> r * (n - i + 1) / i);
        }
    }
    • import java. math. BigInteger;
    • import java. util. stream. *;
    • import java.util.stream.IntStream;
    • public class ArrayFactorial{
    • public static int factorial( int n, int k){
    • int lower= Math. min( k, n- k);
    • int higher= Math. max( k, n- k);
    • return IntStream. range( 2, lower+ 1)
    • . mapToObj( BigInteger:: valueOf)
    • . reduce
    • ( IntStream. range( higher+ 1, n+ 1)
    • . mapToObj( BigInteger:: valueOf)
    • . reduce( BigInteger. ONE, ( a, b)-> a. multiply( b))
    • , ( a, b) -> a. divide( b))
    • . intValue( );
    • public static int factorial(int n, int k) {
    • return IntStream.rangeClosed(1, Math.min(k, n - k))
    • .reduce(1, (r, i) -> r * (n - i + 1) / i);
    • }
    • }