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() {
        var age int
        fmt.Printf("Enter your age on Earth: ")
        _, err := fmt.Scanf("%d", &age)
        if (err != nil) {
            fmt.Println(err)
        }
        age = age * 365 / 687
        fmt.Printf("Your age on the surface of Mars is %d years old.\n", age)
    }
    • package main
    • import "fmt"
    • func main() {
    • age := 28 * 365 / 687
    • fmt.Printf("My age on the surface of Mars is %d years old.
    • ", age)
    • var age int
    • fmt.Printf("Enter your age on Earth: ")
    • _, err := fmt.Scanf("%d", &age)
    • if (err != nil) {
    • fmt.Println(err)
    • }
    • age = age * 365 / 687
    • fmt.Printf("Your age on the surface of Mars is %d years old.
    • ", age)
    • }
Code
Diff
  • const countLetterInSentence = (sentence, letter) => ([...sentence].filter(test => letter === test).length)
    
    function countLettersInSentence(sentence, letters){
      return letters.map(letter => countLetterInSentence(sentence, letter))
    }
    • function testAmount(sentence, letters){
    • return letters.map(letter =>
    • [...sentence].filter(test => letter === test).length)
    • const countLetterInSentence = (sentence, letter) => ([...sentence].filter(test => letter === test).length)
    • function countLettersInSentence(sentence, letters){
    • return letters.map(letter => countLetterInSentence(sentence, letter))
    • }
Code
Diff
  • using System;
    using System.Linq;
    
    public class Kata
    {
        public static int DuplicateCount(string s) => 
            s.ToLower()
                .GroupBy(c => c)
                .Count(g => g.Skip(1).Any());
    }
    • using System;
    • using System.Linq;
    • public class Kata
    • {
    • public static int DuplicateCount(string str)
    • {
    • return str
    • .ToLower()
    • .GroupBy(c => c)
    • .Count (g => g.Count () > 1);
    • }
    • public static int DuplicateCount(string s) =>
    • s.ToLower()
    • .GroupBy(c => c)
    • .Count(g => g.Skip(1).Any());
    • }

Why only 2D and 3D? The universe may contain any number of dimensions! Most popular teories say there are around 6.
Since we are not sure of how many, lets use as backend a function that will work for any number of dimensions: distanceND.

Code
Diff
  • from math import sqrt, pow
    
    # calculate the distance between two points in 2d,3d ... nD
    def distanceND(pA, pB, nD = None):
        dist = 0
        # if a number of dimension was not specified, use the smalest number of dimensions
        if nD is None:
            nD = min(len(pA),len(pB))
        for i in range(nD):
             dist += pow(pA[i] - pB[i], 2);
        return(sqrt(dist));
    
    def distance2D(pA, pB):
        return(distanceND(pA, pB))
        
    def distance3D(pA, pB):
        return(distanceND(pA, pB))
    
    
    • from math import sqrt
    • from math import sqrt, pow
    • # calculate the distance between two points in 2d,3d ... nD
    • def distanceND(pA, pB, nD = None):
    • dist = 0
    • # if a number of dimension was not specified, use the smalest number of dimensions
    • if nD is None:
    • nD = min(len(pA),len(pB))
    • for i in range(nD):
    • dist += pow(pA[i] - pB[i], 2);
    • return(sqrt(dist));
    • def distance2D(pA, pB):
    • if pA == pB: return 0
    • (xA, yA), (xB, yB) = pA, pB
    • return sqrt((xA - xB)**2 + (yA - yB)**2)
    • return(distanceND(pA, pB))
    • 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)
    • return(distanceND(pA, pB))
Code
Diff
  • function isPrime(n) {
        if (n < 2)
          return false;
        // do an early exit for even numbers
        if (n == 2)
          return true;
        if (n % 2 == 0)
          return false;
        // we only have to check odd numbers, starting with 3
        for (var x = 3; x <= Math.floor(Math.sqrt(n)); x += 2)
          if (n % x == 0)
            return false;
        return true;
    }
    • function isPrime(n) {
    • if (n < 2) return false;
    • for (var x = 2; x <= Math.floor(Math.sqrt(n)); x++) {if (n % x == 0) return false;}
    • if (n < 2)
    • return false;
    • // do an early exit for even numbers
    • if (n == 2)
    • return true;
    • if (n % 2 == 0)
    • return false;
    • // we only have to check odd numbers, starting with 3
    • for (var x = 3; x <= Math.floor(Math.sqrt(n)); x += 2)
    • if (n % x == 0)
    • return false;
    • return true;
    • }
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)