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
  • package main
    
    import "fmt"
    
    func main() {
        age := 28 * 365 / 687
        fmt.Print(fmt.Sprintf("My age on the surface of Mars is %d years old.", age))
    }
    • package main
    • import "fmt"
    • func main() {
    • fmt.Print("My age on the surface of Mars is ")
    • fmt.Print(28 * 365 / 687)
    • fmt.Print(" years old.")
    • age := 28 * 365 / 687
    • fmt.Print(fmt.Sprintf("My age on the surface of Mars is %d years old.", age))
    • }
Code
Diff
  • import random
    
    
    def rabinMiller(num):
        s = num - 1
        t = 0
        while s % 2 == 0:
            s = s // 2
            t += 1
    
        for trials in range(5):
            a = random.randrange(2, num - 1)
            v = pow(a, s, num)
            if v != 1:
                i = 0
                while v != (num - 1):
                    if i == t - 1:
                        return False
                    else:
                        i = i + 1
                        v = (v ** 2) % num
        return True
    def is_prime(num):
        if (num < 2):
            return False
        lowPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
        if num in lowPrimes:
            return True
        for prime in lowPrimes:
            if (num % prime == 0):
                return False
        return rabinMiller(num)
    • import random
    • def decompose(n):
    • exponentOfTwo = 0
    • while n % 2 == 0:
    • n = n/2
    • exponentOfTwo += 1
    • return exponentOfTwo, n
    • def isWitness(possibleWitness, p, exponent, remainder):
    • possibleWitness = pow(possibleWitness, remainder, p)
    • if possibleWitness == 1 or possibleWitness == p - 1:
    • return False
    • for _ in range(exponent):
    • possibleWitness = pow(possibleWitness, 2, p)
    • if possibleWitness == p - 1:
    • return False
    • def rabinMiller(num):
    • s = num - 1
    • t = 0
    • while s % 2 == 0:
    • s = s // 2
    • t += 1
    • for trials in range(5):
    • a = random.randrange(2, num - 1)
    • v = pow(a, s, num)
    • if v != 1:
    • i = 0
    • while v != (num - 1):
    • if i == t - 1:
    • return False
    • else:
    • i = i + 1
    • v = (v ** 2) % num
    • return True
    • def is_prime(p, accuracy=100):
    • if p == 2 or p == 3: return True
    • if p < 2: return False
    • exponent, remainder = decompose(p - 1)
    • for _ in range(accuracy):
    • possibleWitness = random.randint(2, p - 2)
    • if isWitness(possibleWitness, p, exponent, remainder):
    • def is_prime(num):
    • if (num < 2):
    • return False
    • lowPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
    • if num in lowPrimes:
    • return True
    • for prime in lowPrimes:
    • if (num % prime == 0):
    • return False
    • return True
    • return rabinMiller(num)

We can turn this into a one-liner (minus the import)

Code
Diff
  • from math import sqrt
    
    is_prime = lambda n: n == 2 or (n > 2 and n % 2 != 0 and all(n % x != 0 for x in range(3, int(sqrt(n)) + 1, 2)))
    
    
    • from math import sqrt
    • is_prime = lambda n: n == 2 or (n > 2 and n % 2 != 0 and all(n % x != 0 for x in range(3, int(sqrt(n)) + 1, 2)))
    • def is_prime(n):
    • if n < 2:
    • return False
    • elif n == 2:
    • return True
    • elif n % 2 == 0:
    • return False
    • for x in range(3, int(sqrt(n)) + 1, 2):
    • if n % x == 0:
    • return False
    • return True
Code
Diff
  • package main
    
    import "fmt"
    
    
    
    func bubble_sort(dataset []int, amout_of_integers int){
      for i := 0; i <= amout_of_integers; i++ {
        for j := amout_of_integers; j >= i + 1; j-- {
          if dataset[j] < dataset[j-1] {
            dataset[j], dataset[j-1] = dataset[j-1], dataset[j] 
          }
        }
      }
    }
    
    
    func main(){
    
      dataset := []int{5, 2, 4, 6, 1, 3};
    
      fmt.Println(dataset)
    
      bubble_sort(dataset, 5);
    
      fmt.Println(dataset)
    }
    
    • package main
    • import "fmt"
    • func swap(dataset []int, a, b int) {
    • var x int = dataset[a]
    • dataset[a] = dataset[b]
    • dataset[b] = x
    • }
    • func bubble_sort(dataset []int, amout_of_integers int){
    • for i := 0; i <= amout_of_integers; i++ {
    • for j := amout_of_integers; j >= i + 1; j-- {
    • if dataset[j] < dataset[j-1] {
    • swap(dataset, j, j - 1)
    • dataset[j], dataset[j-1] = dataset[j-1], dataset[j]
    • }
    • }
    • }
    • }
    • func main(){
    • dataset := []int{5, 2, 4, 6, 1, 3};
    • fmt.Println(dataset)
    • bubble_sort(dataset, 5);
    • fmt.Println(dataset)
    • }
Code
Diff
  • from math import sqrt
    
    def distance2D(pA, pB):
        if pA == pB: return 0
        (xA, yA), (xB, yB) = pA, pB
        return sqrt((xA - xB)**2 + (yA - yB)**2)
        
    def distance3D(pA, pB):
        if pA == pB: return 0
        (xA, yA, zA), (xB, yB, zB) = pA, pB
        return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
    • from math import sqrt
    • def distance2D(pA, pB):
    • if pA == pB: return 0
    • xA, yA = tuple(pA); xB, yB = tuple(pB)
    • (xA, yA), (xB, yB) = pA, pB
    • return sqrt((xA - xB)**2 + (yA - yB)**2)
    • def distance3D(pA, pB):
    • if pA == pB: return 0
    • xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
    • (xA, yA, zA), (xB, yB, zB) = pA, pB
    • return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
Strings
Data Types
Code
Diff
  • from operator import itemgetter
    
    last_char = itemgetter(-1)
    • last_char = lambda s: s[-1]
    • from operator import itemgetter
    • last_char = itemgetter(-1)
Code
Diff
  • public class Dinglemouse {
    
      // Use CSS to display a pretty version of the flap display
      // From: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java
      public static String[] prettyPrint(final String[] lines) {
        String s = "";
        for (int y = 0; y < lines.length; y++) {
          s += "<div style=\"height:23px\">";
          for (int x = 0; x < lines[y].length(); x++) {
            s += "<span style=\"font-size:10px;color:yellow;padding:5px;border:1px solid gray;background:black\">"+lines[y].charAt(x)+"</span>";
          }
          s += "</div>";
        }
        System.out.println(s);
        return lines;
      }
    
    }
    • public class Dinglemouse {
    • // Use CSS to display a pretty version of the flap display
    • // From: https://www.codewars.com/kata/airport-arrivals-slash-departures-number-1/java
    • public static String[] prettyPrint(final String[] lines) {
    • String s = "<pre>";
    • String s = "";
    • for (int y = 0; y < lines.length; y++) {
    • s += "<div style=\"height:23px\">";
    • for (int x = 0; x < lines[y].length(); x++) {
    • s += "<span style=\"font-size:10px;color:yellow;padding:5px;border:1px solid gray;background:black\">"+lines[y].charAt(x)+"</span>";
    • }
    • s += "</div>";
    • }
    • s+= "</pre>";
    • System.out.println(s);
    • return lines;
    • }
    • }
Mathematics
Algorithms
Logic
Numbers
Fundamentals
Code
Diff
  • const dice = _ => -~(Math.random()*6);
    • const dice=_=>~~(Math.random()*6)+1;
    • const dice = _ => -~(Math.random()*6);
Code
Diff
  • const middleCharacter = s => s.slice(~(s.length/2), -~(s.length/2));
    • const middleCharacter = s => s.slice(s.length/2 - !(s.length % 2), s.length/2+1);
    • const middleCharacter = s => s.slice(~(s.length/2), -~(s.length/2));