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 divisors(n)
        fact = []
        for i in 1.. (Math.sqrt(n)).floor
            if n % i == 0 
                fact << i
                # more rubyish i think
                fact << (n / i) if (n / i) != i
            end
        end
        # no need for "return" in ruby
        fact.sort
    end
    • def divisors(n)
    • fact = [];
    • fact = []
    • for i in 1.. (Math.sqrt(n)).floor
    • if n % i == 0
    • fact << i
    • if n / i != i
    • fact << n / i
    • end
    • # more rubyish i think
    • fact << (n / i) if (n / i) != i
    • end
    • end
    • fact.sort!
    • return fact
    • # no need for "return" in ruby
    • fact.sort
    • end
Fundamentals
Arrays
Data Types
Code
Diff
  • var thirdGreatest = (arr) => arr.sort((a,b) => b - a)[2];
    • var thirdGreatest = (arr) => arr.sort((a,b) => a - b)[arr.length - 3];
    • var thirdGreatest = (arr) => arr.sort((a,b) => b - a)[2];

Improve test cases.

Code
Diff
  • #!/bin/bash
    
    if [ $# -eq 1 ]; then
      echo "$(dirname $1), $(basename ${1%.*}), ${1##*.}"
    fi
    • #!/bin/bash
    • filename=$1
    • echo "$(dirname $filename), $(basename ${filename%.*}), ${filename##*.}"
    • if [ $# -eq 1 ]; then
    • echo "$(dirname $1), $(basename ${1%.*}), ${1##*.}"
    • fi
Code
Diff
  • #! /bin/csh -f
    
    echo $2
    • echo $1
    • #! /bin/csh -f
    • echo $2
Code
Diff
  • #!/bin/bash
    
    # Without newline:
    echo -n test
    # With newline
    echo test
    • #!/bin/bash
    • # Without newline:
    • echo -n test
    • # With newline
    • echo test
Code
Diff
  • def sum n
    	(0..n).reduce(:+)
    end
    • def sum n
    • n == 1 ? 1 : n + sum(n - 1)
    • (0..n).reduce(:+)
    • end
Code
Diff
  • # What are all the ways to output a string in Ruby?
    def hello_ruby
      greet = "Hello Ruby!"
    
      print           greet, "\n"
      puts            greet
      print           greet, "\n"
      puts            greet
      $stdout.write   greet + "\n"
      $stdout.puts    greet
      $stdout.print   greet, "\n"
      $stdout <<      greet + "\n"
      (greet+"\n").chars {|c| print c}
    end
    • # What are all the ways to output a string in Ruby?
    • def hello_ruby
    • greet = "Hello Ruby!"
    • print greet, "\n"
    • puts greet
    • print "#{greet}
    • "
    • puts "Hello Ruby!"
    • print greet, "
    • "
    • puts greet
    • $stdout.write greet + "\n"
    • $stdout.puts greet
    • $stdout.print greet, "\n"
    • $stdout << greet + "\n"
    • (greet+"
    • ").each_char {|c| print c}
    • (greet+"
    • ").chars {|c| print c}
    • end
Code
Diff
  • def id_matrix(size):
         return [[i == j for j in range(size)] for i in range(size)]
    
    • def id_matrix(size):
    • return [[1 if i == j else 0 for j in range(size)] for i in range(size)]
    • return [[i == j for j in range(size)] for i in range(size)]
Code
Diff
  • def  getVillianName(birthday):
        return '{} {}'.format(  FIRSTNAME[birthday.strftime("%B")], 
                                LASTNAME[birthday.strftime("%d")[1]])
    
    • def getVillianName(birthday):
    • result = ""
    • result = FIRSTNAME[birthday.strftime("%B")] + " "
    • result += LASTNAME[birthday.strftime("%d")[1]]
    • return result
    • return '{} {}'.format( FIRSTNAME[birthday.strftime("%B")],
    • LASTNAME[birthday.strftime("%d")[1]])
Code
Diff
  • import itertools
    
    
    def eratosthenes():
        # From Coobook recipies
        # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
        # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
        # Tobias Klausmann, David Lees, Raymond Hettinger
        D = {}
        yield 2
        for q in itertools.islice(itertools.count(3), 0, None, 2):
            p = D.pop(q, None)
            if p is None:
                D[q * q] = q
                yield q
            else:
                x = p + q
                while x in D or not (x & 1):
                    x += p
                D[x] = p
    
    
    def count_primes(limit):
        count = 0
        for prime in eratosthenes():
            if prime > limit:
                return count
            count += 1
    • import itertools
    • from itertools import *
    • def eratosthenes():
    • #From Coobook recipies
    • #Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
    • #Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
    • #Tobias Klausmann, David Lees, Raymond Hettinger
    • D = { }
    • # From Coobook recipies
    • # Credits to: Credit: David Eppstein, Tim Peters, Alex Martelli,
    • # Wim Stolker, Kazuo Moriwaka, Hallvard Furuseth, Pierre Denis,
    • # Tobias Klausmann, David Lees, Raymond Hettinger
    • D = {}
    • yield 2
    • for q in itertools.islice(itertools.count(3), 0, None, 2):
    • p = D.pop(q, None)
    • if p is None:
    • D[q*q] = q
    • D[q * q] = q
    • yield q
    • else:
    • x = p + q
    • while x in D or not (x&1):
    • while x in D or not (x & 1):
    • x += p
    • D[x] = p
    • def count_primes(limit):
    • count = 0
    • for prime in eratosthenes():
    • if prime > limit: return count
    • if prime > limit:
    • return count
    • count += 1