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.

### Sum of natural numbers 1..n using recursion

Code
Diff
• ``````
def sum n
n == 1 ? 1 : n + sum(n - 1)
end``````
• def sum n
• def acc(n, s)
• return s if n <= 0 # Base case
• acc(n - 1, s + n) # Recursion step, with accumulator
• end
• acc(n, 0)
• n == 1 ? 1 : n + sum(n - 1)
• end

### Javatlacati&amp;amp;#39;s Kumite #21

Code
Diff
• ``````object Scala extends App {
class Utils {
def upper(entries: String*) = entries.map(_.toUpperCase)
}
System.out.print(new Utils().upper("A", "First", "Scala", "Program") mkString " ")
}``````
• object Scala extends App {
• class StringUtilities {
• def upper(strings: String*): Seq[String] = {
• strings.map((s:String) => s.toUpperCase())
• }
• class Utils {
• def upper(entries: String*) = entries.map(_.toUpperCase)
• }
• val up = new StringUtilities
• Console.println(up.upper("A", "First", "Scala", "Program"))
• System.out.print(new Utils().upper("A", "First", "Scala", "Program") mkString " ")
• }

### Fibonacci Numbers

Finds fibonacci number by given index using iteration

Code
Diff
• ``````(ns fibonacci)

(defn get-fibonacci-number [index]
"Finds fibonacci number by given index using iteration"
(loop [x 0 y 1 z index]
(if (< z 1) x (recur y (+ x y) (dec z)))))``````
• (ns fibonacci)
• (defn get-fibonacci-number [index]
• "Finds fibonacci number by given index"
• (if (<= index 0) 0)
• (if (<= index 2) 1
• (+ (get-fibonacci-number (- index 1))
• (get-fibonacci-number (- index 2)))))
• "Finds fibonacci number by given index using iteration"
• (loop [x 0 y 1 z index]
• (if (< z 1) x (recur y (+ x y) (dec z)))))

### Add Directories to PATH Without Duplicates

Bash

A more succinct version of the function but does require dependencies on tr, sed, and awk. I bet it could be reworked to remove tr and either sed or awk.

Code
Diff
• ``````add_PATH() {
t=\$(echo \$PATH | tr : '\n' | awk '!x[\$0]++' | tr '\n' : | sed 's/.\$//')
echo -n "\$t"
unset t
}

echo "Original Path: \$PATH"
echo "New Path: \$PATH"``````
• oIFS=\$IFS
• IFS=':'
• t=(\${PATH})
• unset IFS
• t=("\$1" \${t[@]%%"\$1"})
• # output the new array
• IFS=':'
• echo -n "\${t[*]}"
• unset t
• IFS=\$oIFS
• t=\$(echo \$PATH | tr : '\n' | awk '!x[\$0]++' | tr '\n' : | sed 's/.\$//')
• echo -n "\$t"
• unset t
• }
• echo "Original Path: \$PATH"
• echo "New Path: \$PATH"

### Callback Chain

Utilities
Asynchronous

In this version `end` is protected so that it is only called once, and once its called `next()` no longer does anything.

Code
Diff
• ``````function Chain(){
}

return this;
}

Chain.prototype.run = function run(end){
var self = this,
ended = false,
_end = function(){
end();
ended = true;
},
next = function(){
if (!ended){
} else {
_end();
}
}
};
next();
}``````
• function Chain(){
• }
• return this;
• }
• Chain.prototype.run = function run(end){
• } else {
• end();
• }
• var self = this,
• ended = false,
• _end = function(){
• end();
• ended = true;
• },
• next = function(){
• if (!ended){
• } else {
• _end();
• }
• }
• };
• next();
• }

### RANDU

Write a generator that given a starting seed (which must be odd), will generate "random" numbers using the infamous RANDU generator, first value should be the seed itself.

Code
Diff
• ``````def randu_seq(x):
while True:
yield x
x = x * 65539 % 0x80000000``````
• (ns randu)
• (defn randu-seq [x] (iterate #(mod (* 65539 %) 0x80000000) x))
• def randu_seq(x):
• while True:
• yield x
• x = x * 65539 % 0x80000000

### Elixir Test

Code
Diff
• ``````sum = &Kernel.+/2
sum.(2,3)``````
• sum = fn(a, b) -> a + b end
• sum = &Kernel.+/2
• sum.(2,3)

### Groovy: Convert your name to japanese

Lists
Data Structures
Strings
Data Types
Code
Diff
• ``````def name = "John Cena"
try {
println "Your name in japanese is " + convertToJapanese(name)
} catch(e) {
System.err << e.getMessage()
}

static String convertToJapanese(String name) {

name = name.toLowerCase()

if(name == "" || !name.matches('^[a-z\\s]*\$'))
throw new Exception('ERROR: invalid name\n')

def alphabet = [
'ka','zu','mi','te','ku',
'lu','ji','ri','ki','zus',
'me','ta','rin','to','mo',
'no','ke','shi','ari','chi',
'do','ru','mei','na','fu','zi'
]

String japaneseName = ''

name.each {
if(it in [' ', '\t', '\n'])
japaneseName += ' '
else
japaneseName += alphabet[((int)it) - 97]
}

japaneseName.split(' ').collect{it.capitalize()}.join(' ')
}``````
• def name = "John Cena"
• try {
• println "Your name in japanese is " + convertToJapanese(name)
• } catch(e) {
• System.err << e.getMessage()
• }
• static String convertToJapanese(String name) {
• name = name.toLowerCase()
• if(name == "" || !name.matches('^[a-z\\s]*\$'))
• throw new Exception('ERROR: invalid name\n')
• def alphabet = [
• 'ka','zu','mi','te','ku',
• 'lu','ji','ri','ki','zus',
• 'me','ta','rin','to','mo',
• 'no','ke','shi','ari','chi',
• 'do','ru','mei','na','fu','zi'
• ]
• String japaneseName = ''
• name.each {
• if(it in [' ', '\t', '\n'])
• japanaseName += ' '
• japaneseName += ' '
• else
• japanaseName += alphabet[((int)it) - 97]
• japaneseName += alphabet[((int)it) - 97]
• }
• japanaseName.split(' ').collect{it.capitalize()}.join(' ')
• japaneseName.split(' ').collect{it.capitalize()}.join(' ')
• }