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
Strings
Code
Diff
  • roll_dice=lambda d:[__import__("random").randint(1,int(d.split("d")[1]))for _ in range(int(d.split("d")[0]))]
    • import random
    • def roll_dice(dice):
    • r,s=map(int,dice.split('d'))
    • return[random.randint(1,s)for _ in range(r)]
    • roll_dice=lambda d:[__import__("random").randint(1,int(d.split("d")[1]))for _ in range(int(d.split("d")[0]))]
Code
Diff
  • Greeting=lambda name,rank=None,formal=False: lambda:f'He{["y","llo"][formal]}, {[str(rank)+" ",""][not rank or not formal]}{name}{chr(33+formal*13)}'
    • Greeting=lambda name,rank=None,formal=False: lambda:f'He{["y","llo"][formal]}, {[str(rank)+" ",""][rank is None or not formal]}{name}{chr(33+formal*13)}'
    • Greeting=lambda name,rank=None,formal=False: lambda:f'He{["y","llo"][formal]}, {[str(rank)+" ",""][not rank or not formal]}{name}{chr(33+formal*13)}'

a kotlin more idiomatic way and with Long instead of Int

Code
Diff
  • fun fact(n: Long): Long = n.let { 
                require(it > 0L)
                (2L..it).fold(1L, Long::times)
            }
    • fun fact(n: Int):Int {
    • return if (n == 0) 1
    • else fact(n-1) * n
    • }
    • fun fact(n: Long): Long = n.let {
    • require(it > 0L)
    • (2L..it).fold(1L, Long::times)
    • }
Code
Diff
  • fun returnNum(n:Int)=n
    
    • fun returnNum(n:Int): Int{
    • return n
    • }
    • fun returnNum(n:Int)=n
Code
Diff
  • def calculate_min_run(n):
        r = 0
        while n >= 32:
            r |= n & 1
            n >>= 1
        return n + r
    
    def insertion_sort(arr, left, right):
        for i in range(left + 1, right + 1):
            j = i
            while j > left and arr[j] < arr[j - 1]:
                arr[j], arr[j - 1] = arr[j - 1], arr[j]
                j -= 1
    
    def merge(arr, l, m, r):
        len1, len2 = m - l + 1, r - m
        left, right = [], []
        for i in range(0, len1):
            left.append(arr[l + i])
        for i in range(0, len2):
            right.append(arr[m + 1 + i])
    
        i, j, k = 0, 0, l
    
        while i < len1 and j < len2:
            if left[i] <= right[j]:
                arr[k] = left[i]
                i += 1
    
            else:
                arr[k] = right[j]
                j += 1
    
            k += 1
    
        while i < len1:
            arr[k] = left[i]
            k += 1
            i += 1
    
        while j < len2:
            arr[k] = right[j]
            k += 1
            j += 1
    
    def tim_sort(arr):
        n = len(arr)
        min_run = calculate_min_run(n)
    
        for start in range(0, n, min_run):
            end = min(start + min_run - 1, n - 1)
            insertion_sort(arr, start, end)
    
        size = min_run
        while size < n:
            for left in range(0, n, 2 * size):
                mid = min(n - 1, left + size - 1)
                right = min((left + 2 * size - 1), (n - 1))
    
                if mid < right:
                    merge(arr, left, mid, right)
    
            size = 2 * size
            
    tim_sort([1, 2, 3])
    • a = [1,2,3]
    • a = sorted(a)
    • def calculate_min_run(n):
    • r = 0
    • while n >= 32:
    • r |= n & 1
    • n >>= 1
    • return n + r
    • def insertion_sort(arr, left, right):
    • for i in range(left + 1, right + 1):
    • j = i
    • while j > left and arr[j] < arr[j - 1]:
    • arr[j], arr[j - 1] = arr[j - 1], arr[j]
    • j -= 1
    • def merge(arr, l, m, r):
    • len1, len2 = m - l + 1, r - m
    • left, right = [], []
    • for i in range(0, len1):
    • left.append(arr[l + i])
    • for i in range(0, len2):
    • right.append(arr[m + 1 + i])
    • i, j, k = 0, 0, l
    • while i < len1 and j < len2:
    • if left[i] <= right[j]:
    • arr[k] = left[i]
    • i += 1
    • else:
    • arr[k] = right[j]
    • j += 1
    • k += 1
    • while i < len1:
    • arr[k] = left[i]
    • k += 1
    • i += 1
    • while j < len2:
    • arr[k] = right[j]
    • k += 1
    • j += 1
    • def tim_sort(arr):
    • n = len(arr)
    • min_run = calculate_min_run(n)
    • for start in range(0, n, min_run):
    • end = min(start + min_run - 1, n - 1)
    • insertion_sort(arr, start, end)
    • size = min_run
    • while size < n:
    • for left in range(0, n, 2 * size):
    • mid = min(n - 1, left + size - 1)
    • right = min((left + 2 * size - 1), (n - 1))
    • if mid < right:
    • merge(arr, left, mid, right)
    • size = 2 * size
    • tim_sort([1, 2, 3])
Code
Diff
  • const reverseStr = str => Array.from(str).reverse().join("")
    
    console.log(reverseStr('hello world'));
    • // const reverseStr = str => [...str].reverse().join(''); <-- weak smh
    • function reverseStr(str){return str.split("").reverse().join("")}
    • const reverseStr = str => Array.from(str).reverse().join("")
    • console.log(reverseStr('hello world'));
Code
Diff
  • module AreThereThree where
    
    solution :: Int -> Bool
    solution = elem '3' . show
    • module AreThereThree where
    • import Control.Monad (liftM2)
    • solution :: Int -> Bool
    • solution = (elem '3') . show
    • solution = elem '3' . show
Fundamentals
Games
Code
Diff
  • def riddle(w) = w=~/\?/
    • def riddle(w) = w.index("?")
    • def riddle(w) = w=~/\?/
Code
Diff
  • def verify_sum(a, b)
     a&&b&&a.sum==b.sum||false
    end
    
    • def verify_sum(a, b)
    • return false if a.nil? || b.nil?
    • a.sum == b.sum
    • a&&b&&a.sum==b.sum||false
    • end