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.
struct Person { first_name: String, last_name: String, } impl Person { fn greet(&self) -> String { format!("Hello, my name is {} {}", self.first_name, self.last_name) } } fn person_builder(first_name: &str, last_name: &str) -> Person { Person { first_name: first_name.to_owned(), last_name: last_name.to_owned() } }
// Code is in the preload- struct Person {
- first_name: String,
- last_name: String,
- }
- impl Person {
- fn greet(&self) -> String {
- format!("Hello, my name is {} {}", self.first_name, self.last_name)
- }
- }
- fn person_builder(first_name: &str, last_name: &str) -> Person {
Person { first_name: first_name.into(), last_name: last_name.into() }- Person { first_name: first_name.to_owned(), last_name: last_name.to_owned() }
- }
Scott numerals are slightly less slow than Church numerals in this kata
const code = String.raw` # JohanWiltink B = \ f g x . f (g x) I = \ x . x K = \ x _ . x Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) ) True = \ t f . t False = \ t f . f Succ = \ n z s . s n Pred = \ n . n 0 I Plus = \ m n . m n (B Succ (Plus n)) Minus = \ m n . m 0 (B (n m) Minus) Times = \ m n . m 0 (B (Plus n) (Times n)) isZero = \ n . n True (K False) isNotZero = \ n . n False (K True) And = \ x y . x y x Or = \ x . x x GT = \ x y . isNotZero (Minus x y) Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m) # function isPrime(n) { # const trial = function trial(i) { # return i * i > n || n % i != 0 && trial(i+1) ; # } ; # return n > 1 && trial(2) ; # } isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) ) ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) ) `
- const code = String.raw`
- # JohanWiltink
- B = \ f g x . f (g x)
- I = \ x . x
- K = \ x _ . x
- Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
- True = \ t f . t
- False = \ t f . f
Succ = \ n s z . s (n s z)Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.xMinus = \ m n . n Pred mTimes = \ m n s . m (n s)isZero = \ n . n (\_.False) TrueisNotZero = \ n . n (\_.True) False- Succ = \ n z s . s n
- Pred = \ n . n 0 I
- Plus = \ m n . m n (B Succ (Plus n))
- Minus = \ m n . m 0 (B (n m) Minus)
- Times = \ m n . m 0 (B (Plus n) (Times n))
- isZero = \ n . n True (K False)
- isNotZero = \ n . n False (K True)
- And = \ x y . x y x
- Or = \ x . x x
- GT = \ x y . isNotZero (Minus x y)
- Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
- # function isPrime(n) {
- # const trial = function trial(i) {
- # return i * i > n || n % i != 0 && trial(i+1) ;
- # } ;
- # return n > 1 && trial(2) ;
- # }
- isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
- ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
- `
const chai = require("chai"); chai.config.truncateThreshold = 0; const {assert} = chai; // const LC = require("../../src/lambda-calculus.js"); const LC = { compile: () => compile(code), config } // Temporary. Would normally import, see line above. LC.config.purity = "LetRec"; LC.config.numEncoding = "Scott"; const {isPrime} = LC.compile(); // const fromInt = LC.fromIntWith(LC.config); it("fixed tests", function() { this.timeout(12e3); assert.equal( isPrime(fromInt( 0)) (true)(false), false ); assert.equal( isPrime(fromInt( 1)) (true)(false), false ); assert.equal( isPrime(fromInt( 2)) (true)(false), true ); assert.equal( isPrime(fromInt( 3)) (true)(false), true ); assert.equal( isPrime(fromInt( 4)) (true)(false), false ); assert.equal( isPrime(fromInt( 5)) (true)(false), true ); assert.equal( isPrime(fromInt( 6)) (true)(false), false ); assert.equal( isPrime(fromInt( 7)) (true)(false), true ); assert.equal( isPrime(fromInt( 8)) (true)(false), false ); assert.equal( isPrime(fromInt( 9)) (true)(false), false ); assert.equal( isPrime(fromInt(10)) (true)(false), false ); assert.equal( isPrime(fromInt(11)) (true)(false), true ); assert.equal( isPrime(fromInt(12)) (true)(false), false ); assert.equal( isPrime(fromInt(13)) (true)(false), true ); assert.equal( isPrime(fromInt(14)) (true)(false), false ); assert.equal( isPrime(fromInt(15)) (true)(false), false ); assert.equal( isPrime(fromInt(16)) (true)(false), false ); assert.equal( isPrime(fromInt(17)) (true)(false), true ); assert.equal( isPrime(fromInt(18)) (true)(false), false ); assert.equal( isPrime(fromInt(19)) (true)(false), true ); });
- const chai = require("chai");
const assert = chai.assert;- chai.config.truncateThreshold = 0;
- const {assert} = chai;
// const LC = require("LC");- // const LC = require("../../src/lambda-calculus.js");
- const LC = { compile: () => compile(code), config } // Temporary. Would normally import, see line above.
- LC.config.purity = "LetRec";
LC.config.numEncoding = "Church";- LC.config.numEncoding = "Scott";
const solution = LC.compile();const {isPrime} = solution;- const {isPrime} = LC.compile();
- // const fromInt = LC.fromIntWith(LC.config);
describe("Sample Tests", function() {it("Basics", function() {assert.equal(isPrime(0) (true)(false), false);assert.equal(isPrime(1) (true)(false), false);assert.equal(isPrime(2) (true)(false), true);assert.equal(isPrime(3) (true)(false), true);assert.equal(isPrime(4) (true)(false), false);assert.equal(isPrime(5) (true)(false), true);assert.equal(isPrime(6) (true)(false), false);assert.equal(isPrime(7) (true)(false), true);assert.equal(isPrime(8) (true)(false), false);assert.equal(isPrime(9) (true)(false), false);assert.equal(isPrime(10) (true)(false), false);assert.equal(isPrime(11) (true)(false), true);assert.equal(isPrime(12) (true)(false), false);assert.equal(isPrime(13) (true)(false), true);assert.equal(isPrime(14) (true)(false), false);assert.equal(isPrime(15) (true)(false), false);assert.equal(isPrime(16) (true)(false), false);assert.equal(isPrime(17) (true)(false), true);assert.equal(isPrime(18) (true)(false), false);assert.equal(isPrime(19) (true)(false), true);});- it("fixed tests", function() {
- this.timeout(12e3);
- assert.equal( isPrime(fromInt( 0)) (true)(false), false );
- assert.equal( isPrime(fromInt( 1)) (true)(false), false );
- assert.equal( isPrime(fromInt( 2)) (true)(false), true );
- assert.equal( isPrime(fromInt( 3)) (true)(false), true );
- assert.equal( isPrime(fromInt( 4)) (true)(false), false );
- assert.equal( isPrime(fromInt( 5)) (true)(false), true );
- assert.equal( isPrime(fromInt( 6)) (true)(false), false );
- assert.equal( isPrime(fromInt( 7)) (true)(false), true );
- assert.equal( isPrime(fromInt( 8)) (true)(false), false );
- assert.equal( isPrime(fromInt( 9)) (true)(false), false );
- assert.equal( isPrime(fromInt(10)) (true)(false), false );
- assert.equal( isPrime(fromInt(11)) (true)(false), true );
- assert.equal( isPrime(fromInt(12)) (true)(false), false );
- assert.equal( isPrime(fromInt(13)) (true)(false), true );
- assert.equal( isPrime(fromInt(14)) (true)(false), false );
- assert.equal( isPrime(fromInt(15)) (true)(false), false );
- assert.equal( isPrime(fromInt(16)) (true)(false), false );
- assert.equal( isPrime(fromInt(17)) (true)(false), true );
- assert.equal( isPrime(fromInt(18)) (true)(false), false );
- assert.equal( isPrime(fromInt(19)) (true)(false), true );
- });
def fizz_buzz(m): return ["Fizz"*int(n%3==0)+"Buzz"*int(n%5==0) if (n%3==0 or n%5==0) else n for n in range(1,m)]
def fizz_buzz(n):return ['FizzBuzz' if (i % 15 == 0) else 'Fizz' if(i % 3 == 0) else 'Buzz' if(i % 5 == 0) else i for i in range(1,n)]- def fizz_buzz(m):
- return ["Fizz"*int(n%3==0)+"Buzz"*int(n%5==0) if (n%3==0 or n%5==0) else n for n in range(1,m)]
actual = list(fizz_buzz(17)) expected = [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16] test.assert_equals(actual, expected)
- actual = list(fizz_buzz(17))
- expected = [1, 2, 'Fizz', 4, 'Buzz', 'Fizz', 7, 8, 'Fizz', 'Buzz', 11, 'Fizz', 13, 14, 'FizzBuzz', 16]
Test.assert_equals(actual, expected)- test.assert_equals(actual, expected)
def convert_decimal_roman(number: int) -> str: try: number = int(number) except ValueError: print("Invalid Input, Value Error") return("Invalid Input") str = '' numDct = {1000: "M", 900: "CM", 500: "D", 400: "CD", 100: "C", 90: "XC", 50: "L", 40: "XL", 10: "X", 9: "IX", 5: "V", 4: "IV", 1: "I"} decimals = [] for key, value in numDct.items(): decimals.append(value * (number // key)) number %= key return "".join(decimals)
def convert_decimal_roman(number):- def convert_decimal_roman(number: int) -> str:
- try:
- number = int(number)
- except ValueError:
- print("Invalid Input, Value Error")
- return("Invalid Input")
- str = ''
- numDct = {1000: "M",
- 900: "CM",
- 500: "D",
- 400: "CD",
- 100: "C",
- 90: "XC",
- 50: "L",
- 40: "XL",
- 10: "X",
- 9: "IX",
- 5: "V",
- 4: "IV",
- 1: "I"}
- decimals = []
- for key, value in numDct.items():
str += value * (number // key)- decimals.append(value * (number // key))
- number %= key
return str- return "".join(decimals)
public class FizzBuzz { public string GetOutput(int number) { if (number % 15 == 0) return "FizzBuzz"; else if (number % 3 == 0) return "Fizz"; else if (number % 5 == 0) return "Buzz"; else return number.ToString(); // Fizz buzz is a popular computer science interview question. // The function above is given a number - if the number is // divisible by 3, return "fizz", if it's divisible by 5, // return "buzz", if not divisble by 3 or 5 - return the // number itself. } }
- public class FizzBuzz
- {
- public string GetOutput(int number) {
if (number % 15 == 0) {return "FizzBuzz";}else if (number % 3 == 0) {return "Fizz";}else if (number % 5 == 0) {return "Buzz";}else {return number.ToString();}- if (number % 15 == 0) return "FizzBuzz";
- else if (number % 3 == 0) return "Fizz";
- else if (number % 5 == 0) return "Buzz";
- else return number.ToString();
- // Fizz buzz is a popular computer science interview question.
- // The function above is given a number - if the number is
- // divisible by 3, return "fizz", if it's divisible by 5,
- // return "buzz", if not divisble by 3 or 5 - return the
- // number itself.
- }
- }