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.
get_fibs=lambda a=1,b=1:[(t:=a,a:=b,b:=b+t)[0]for _ in range(100)]
def output(thing=[1,1]):for _ in range(100): thing.append(thing[-1]+thing[-2])return thing- get_fibs=lambda a=1,b=1:[(t:=a,a:=b,b:=b+t)[0]for _ in range(100)]
import codewars_test as test from solution import get_fibs @test.describe("Example") def test_group(): @test.it("test case") def test_case(): fibs = get_fibs() test.assert_equals(fibs, [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685, 37889062373143906, 61305790721611591, 99194853094755497, 160500643816367088, 259695496911122585, 420196140727489673, 679891637638612258, 1100087778366101931, 1779979416004714189, 2880067194370816120, 4660046610375530309, 7540113804746346429, 12200160415121876738, 19740274219868223167, 31940434634990099905, 51680708854858323072, 83621143489848422977, 135301852344706746049, 218922995834555169026, 354224848179261915075]) test.assert_equals(len(fibs), 100)
- import codewars_test as test
# TODO Write testsfrom solution import output # or from solution import example- from solution import get_fibs
# test.assert_equals(actual, expected, [optional] message)- @test.describe("Example")
- def test_group():
- @test.it("test case")
- def test_case():
test.assert_equals(output(), [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685, 37889062373143906, 61305790721611591, 99194853094755497, 160500643816367088, 259695496911122585, 420196140727489673, 679891637638612258, 1100087778366101931, 1779979416004714189, 2880067194370816120, 4660046610375530309, 7540113804746346429, 12200160415121876738, 19740274219868223167, 31940434634990099905, 51680708854858323072, 83621143489848422977, 135301852344706746049, 218922995834555169026, 354224848179261915075, 573147844013817084101, 927372692193078999176])- fibs = get_fibs()
- test.assert_equals(fibs, [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685, 37889062373143906, 61305790721611591, 99194853094755497, 160500643816367088, 259695496911122585, 420196140727489673, 679891637638612258, 1100087778366101931, 1779979416004714189, 2880067194370816120, 4660046610375530309, 7540113804746346429, 12200160415121876738, 19740274219868223167, 31940434634990099905, 51680708854858323072, 83621143489848422977, 135301852344706746049, 218922995834555169026, 354224848179261915075])
- test.assert_equals(len(fibs), 100)
function Sum-OfPositive($NumberArray) { [Func[int,bool]]$Delegate = {param($v); return $v -ge 0} [Linq.Enumerable]::Sum([Linq.Enumerable]::Where([int[]]$NumberArray,$Delegate)) }
- function Sum-OfPositive($NumberArray)
- {
($NumberArray | ?{$_ -gt 0} | Measure -sum).Sum- [Func[int,bool]]$Delegate = {param($v); return $v -ge 0}
- [Linq.Enumerable]::Sum([Linq.Enumerable]::Where([int[]]$NumberArray,$Delegate))
- }
const chai = require("chai"); const assert = chai.assert; describe("XOR", ()=> { it("some information about badal sherpuja", ()=> { assert.strictEqual(XOR(true,false), true); assert.strictEqual(XOR(false,true), true); }); it("my name is nikhil danekhu", ()=> { assert.strictEqual(XOR(true,true), false); assert.strictEqual(XOR(false,false), false); }); let fileContent = require("fs").readFileSync("/workspace/solution.txt", "utf8"); it("would you like to earn money", ()=> { assert.isTrue(fileContent.length <= 35, `Your solution is ${fileContent.length-35} character${fileContent.length!=36 ? 's' : ''} over the length limit`); }) it("handsome !=(=) and ==(=)", ()=> { assert.isFalse(fileContent.includes('!='), 'Your solution uses !=(=)'); assert.isFalse(fileContent.includes('=='), 'Your solution uses ==(=)'); }) it("should pass random tests", ()=> { let a; let b; for(let i=0;i<420;i++) { a = Math.random() < 0.5; b = Math.random() < 0.5; assert.strictEqual(XOR(a,b), a != b); } }) });
- const chai = require("chai");
- const assert = chai.assert;
- describe("XOR", ()=> {
it("should return true for different bools", ()=> {- it("some information about badal sherpuja", ()=> {
- assert.strictEqual(XOR(true,false), true);
- assert.strictEqual(XOR(false,true), true);
- });
it("should return false for same bools", ()=> {- it("my name is nikhil danekhu", ()=> {
- assert.strictEqual(XOR(true,true), false);
- assert.strictEqual(XOR(false,false), false);
- });
- let fileContent = require("fs").readFileSync("/workspace/solution.txt", "utf8");
it("should be shorter than 30 characters", ()=> {- it("would you like to earn money", ()=> {
- assert.isTrue(fileContent.length <= 35, `Your solution is ${fileContent.length-35} character${fileContent.length!=36 ? 's' : ''} over the length limit`);
- })
it("shouldn't use !=(=) and ==(=)", ()=> {- it("handsome !=(=) and ==(=)", ()=> {
- assert.isFalse(fileContent.includes('!='), 'Your solution uses !=(=)');
- assert.isFalse(fileContent.includes('=='), 'Your solution uses ==(=)');
- })
- it("should pass random tests", ()=> {
- let a; let b;
- for(let i=0;i<420;i++) {
- a = Math.random() < 0.5;
- b = Math.random() < 0.5;
- assert.strictEqual(XOR(a,b), a != b);
- }
- })
- });
Added a small benchmark, the output can be shown with "cargo test -- --nocapture" locally.
pub fn sort_desc(mut n: u64) -> u64 { let mut digit_counts = [0; 10]; while n > 0 { let digit = (n % 10) as usize; digit_counts[digit] += 1; n /= 10; } let mut result = 0; let mut fac = 1; for digit in 0..10 { for _ in 0..digit_counts[digit] { result += (digit as u64) * fac; fac *= 10; } } result } use std::iter::repeat; pub fn sort_desc_it(mut n: u64) -> u64 { let mut digit_counts = [0; 10]; while n > 0 { digit_counts[n as usize % 10] += 1; n /= 10; } digit_counts .into_iter() .enumerate() .rev() .flat_map(|(digit, count)| repeat(digit as u64).take(count)) .fold(0, |result, digit| result * 10 + digit) } use std::time::Instant; fn benchmark<F>(func: F, input: u64, iterations: u32) -> (u64, f64) where F: Fn(u64) -> u64, { let mut total_duration = 0.0; let mut result = 0; for _ in 0..iterations { let start = Instant::now(); result = func(input); let duration = start.elapsed(); total_duration += duration.as_secs_f64(); } let avg_duration = total_duration / iterations as f64; (result, avg_duration) }
- pub fn sort_desc(mut n: u64) -> u64 {
- let mut digit_counts = [0; 10];
- while n > 0 {
- let digit = (n % 10) as usize;
- digit_counts[digit] += 1;
- n /= 10;
- }
- let mut result = 0;
- let mut fac = 1;
- for digit in 0..10 {
- for _ in 0..digit_counts[digit] {
- result += (digit as u64) * fac;
- fac *= 10;
- }
- }
- result
- }
- use std::iter::repeat;
pub fn sort_desc(mut n: u64) -> u64 {- pub fn sort_desc_it(mut n: u64) -> u64 {
- let mut digit_counts = [0; 10];
- while n > 0 {
- digit_counts[n as usize % 10] += 1;
- n /= 10;
- }
- digit_counts
- .into_iter()
- .enumerate()
- .rev()
- .flat_map(|(digit, count)| repeat(digit as u64).take(count))
- .fold(0, |result, digit| result * 10 + digit)
}- }
- use std::time::Instant;
- fn benchmark<F>(func: F, input: u64, iterations: u32) -> (u64, f64)
- where
- F: Fn(u64) -> u64,
- {
- let mut total_duration = 0.0;
- let mut result = 0;
- for _ in 0..iterations {
- let start = Instant::now();
- result = func(input);
- let duration = start.elapsed();
- total_duration += duration.as_secs_f64();
- }
- let avg_duration = total_duration / iterations as f64;
- (result, avg_duration)
- }
#[cfg(test)] mod tests { use super::*; fn do_test(number: u64, expected: u64) { let actual = sort_desc(number); assert_eq!( actual, expected, "For {} expected {} but got {}", number, expected, actual ); } #[test] fn test_sort_desc() { do_test(0, 0); do_test(1, 1); do_test(12, 21); do_test(123, 321); do_test(310, 310); do_test(12034, 43210); do_test(12345, 54321); do_test(123456789, 987654321); do_test(1234567890, 9876543210); } #[test] fn benchmark_max_num() { let numbers = vec![ 1234567890, 9876543210, 112233445566778899, 987654321987654321, ]; let iterations = 1000; for (ix, func) in [sort_desc, sort_desc_it].iter().enumerate() { if ix == 0 { println!("sort_desc:"); } else { println!("sort_desc_it:"); } for &number in &numbers { let (result, avg_duration) = benchmark(func, number, iterations); println!( "Max number formed from {}: {} (average time: {:.9} seconds)", number, result, avg_duration ); } } } }
- #[cfg(test)]
- mod tests {
use super::sort_desc;- use super::*;
- fn do_test(number: u64, expected: u64) {
- let actual = sort_desc(number);
assert_eq!(actual, expected, "For {} expected {} but got {}", number, expected, actual);- assert_eq!(
- actual, expected,
- "For {} expected {} but got {}",
- number, expected, actual
- );
- }
- #[test]
- fn test_sort_desc() {
- do_test(0, 0);
- do_test(1, 1);
- do_test(12, 21);
- do_test(123, 321);
- do_test(310, 310);
- do_test(12034, 43210);
- do_test(12345, 54321);
- do_test(123456789, 987654321);
- do_test(1234567890, 9876543210);
- }
- #[test]
- fn benchmark_max_num() {
- let numbers = vec![
- 1234567890,
- 9876543210,
- 112233445566778899,
- 987654321987654321,
- ];
- let iterations = 1000;
- for (ix, func) in [sort_desc, sort_desc_it].iter().enumerate() {
- if ix == 0 {
- println!("sort_desc:");
- } else {
- println!("sort_desc_it:");
- }
- for &number in &numbers {
- let (result, avg_duration) = benchmark(func, number, iterations);
- println!(
- "Max number formed from {}: {} (average time: {:.9} seconds)",
- number, result, avg_duration
- );
- }
- }
- }
- }