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.
// PHPUnit Test Examples: // TODO: Replace examples and use TDD development by writing your own tests class MyTestCases extends TestCase { // test function names should start with "test" public function testThatSomethingShouldHappen() { $this->assertEquals("a", "a"); $this->assertEquals([0], [0]); } }
- // PHPUnit Test Examples:
- // TODO: Replace examples and use TDD development by writing your own tests
- class MyTestCases extends TestCase
- {
- // test function names should start with "test"
- public function testThatSomethingShouldHappen() {
- $this->assertEquals("a", "a");
- $this->assertEquals([0], [0]);
- }
- }
const whoShouldServe = (scoreLeft, scoreRight, servesCount) => { return Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second'; };
function whoShouldServe($scoreLeft, $scoreRight, $servesCount) {return floor(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second';- const whoShouldServe = (scoreLeft, scoreRight, servesCount) => {
- return Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second';
- };
describe("Solution", function(){ it("Basic tests", function(){ a = whoShouldServe(0, 0, 2); Test.assertEquals(a, 'first', "expected: 'first' got: " + a); assert.strictEqual(a, 'first'); a = whoShouldServe(1, 0, 2); Test.assertEquals(a, 'first', "expected: 'first' got: " + a); assert.strictEqual(a, 'first'); a = whoShouldServe(1, 2, 2); Test.assertEquals(a, 'second', "expected: 'second' got: " + a); assert.strictEqual(a, 'second'); a = whoShouldServe(1, 3, 2); Test.assertEquals(a, 'first', "expected: 'first' got: " + a); assert.strictEqual(a, 'first'); a = whoShouldServe(7, 8, 2); Test.assertEquals(a, 'second', "expected: 'second' got: " + a); assert.strictEqual(a, 'second'); a = whoShouldServe(7, 8, 5); Test.assertEquals(a, 'second', "expected: 'second' got: " + a); assert.strictEqual(a, 'second'); a = whoShouldServe(0, 6, 5); Test.assertEquals(a, 'second', "expected: 'second' got: " + a); assert.strictEqual(a, 'second'); a = whoShouldServe(1, 10, 5); Test.assertEquals(a, 'first', "expected: 'first' got: " + a); assert.strictEqual(a, 'first'); }); const whoIs = (scoreLeft, scoreRight, servesCount) => Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second'; const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min; it("Random tests", function(){ scoreLeft = getRandomInt(1, 12); scoreRight = getRandomInt(1, 12); a = whoShouldServe(scoreLeft, scoreRight, 2); Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a); assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2)); scoreLeft = getRandomInt(1, 12); scoreRight = getRandomInt(1, 12); a = whoShouldServe(scoreLeft, scoreRight, 2); Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a); assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2)); scoreLeft = getRandomInt(1, 12); scoreRight = getRandomInt(1, 12); a = whoShouldServe(scoreLeft, scoreRight, 2); Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a); assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2)); scoreLeft = getRandomInt(1, 12); scoreRight = getRandomInt(1, 12); a = whoShouldServe(scoreLeft, scoreRight, 2); Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a); assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2)); scoreLeft = getRandomInt(1, 12); scoreRight = getRandomInt(1, 12); a = whoShouldServe(scoreLeft, scoreRight, 2); Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a); assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2)); }); });
class EqualsTest extends TestCase{public function testBasic(){$a = whoShouldServe(0, 0, 2);$this->assertEquals($a, 'first');$a = whoShouldServe(1, 0, 2);$this->assertEquals($a, 'first');$a = whoShouldServe(1, 2, 2);$this->assertEquals($a, 'second');$a = whoShouldServe(1, 3, 2);$this->assertEquals($a, 'first');$a = whoShouldServe(7, 8, 2);$this->assertEquals($a, 'second');$a = whoShouldServe(7, 8, 5);$this->assertEquals($a, 'second');$a = whoShouldServe(0, 6, 5);$this->assertEquals($a, 'second');$a = whoShouldServe(1, 10, 5);$this->assertEquals($a, 'first');}protected function whoIs($scoreLeft, $scoreRight, $servesCount) {return floor(($scoreLeft + $scoreRight) / $servesCount) % 2 === 0 ? 'first' : 'second';}public function testRandom(){$scoreLeft = rand(1, 11);$scoreRight = rand(1, 11);$a = whoShouldServe($scoreLeft, $scoreRight, 2);$this->assertEquals($a, $this->whoIs($scoreLeft, $scoreRight, 2));$scoreLeft = rand(1, 11);$scoreRight = rand(1, 11);$a = whoShouldServe($scoreLeft, $scoreRight, 2);$this->assertEquals($a, $this->whoIs($scoreLeft, $scoreRight, 2));$scoreLeft = rand(1, 11);$scoreRight = rand(1, 11);$a = whoShouldServe($scoreLeft, $scoreRight, 2);$this->assertEquals($a, $this->whoIs($scoreLeft, $scoreRight, 2));$scoreLeft = rand(1, 11);$scoreRight = rand(1, 11);$a = whoShouldServe($scoreLeft, $scoreRight, 2);$this->assertEquals($a, $this->whoIs($scoreLeft, $scoreRight, 2));$scoreLeft = rand(1, 11);$scoreRight = rand(1, 11);$a = whoShouldServe($scoreLeft, $scoreRight, 2);$this->assertEquals($a, $this->whoIs($scoreLeft, $scoreRight, 2));}}- describe("Solution", function(){
- it("Basic tests", function(){
- a = whoShouldServe(0, 0, 2);
- Test.assertEquals(a, 'first', "expected: 'first' got: " + a);
- assert.strictEqual(a, 'first');
- a = whoShouldServe(1, 0, 2);
- Test.assertEquals(a, 'first', "expected: 'first' got: " + a);
- assert.strictEqual(a, 'first');
- a = whoShouldServe(1, 2, 2);
- Test.assertEquals(a, 'second', "expected: 'second' got: " + a);
- assert.strictEqual(a, 'second');
- a = whoShouldServe(1, 3, 2);
- Test.assertEquals(a, 'first', "expected: 'first' got: " + a);
- assert.strictEqual(a, 'first');
- a = whoShouldServe(7, 8, 2);
- Test.assertEquals(a, 'second', "expected: 'second' got: " + a);
- assert.strictEqual(a, 'second');
- a = whoShouldServe(7, 8, 5);
- Test.assertEquals(a, 'second', "expected: 'second' got: " + a);
- assert.strictEqual(a, 'second');
- a = whoShouldServe(0, 6, 5);
- Test.assertEquals(a, 'second', "expected: 'second' got: " + a);
- assert.strictEqual(a, 'second');
- a = whoShouldServe(1, 10, 5);
- Test.assertEquals(a, 'first', "expected: 'first' got: " + a);
- assert.strictEqual(a, 'first');
- });
- const whoIs = (scoreLeft, scoreRight, servesCount) => Math.floor((scoreLeft + scoreRight) / servesCount) % 2 === 0 ? 'first' : 'second';
- const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
- it("Random tests", function(){
- scoreLeft = getRandomInt(1, 12);
- scoreRight = getRandomInt(1, 12);
- a = whoShouldServe(scoreLeft, scoreRight, 2);
- Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a);
- assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2));
- scoreLeft = getRandomInt(1, 12);
- scoreRight = getRandomInt(1, 12);
- a = whoShouldServe(scoreLeft, scoreRight, 2);
- Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a);
- assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2));
- scoreLeft = getRandomInt(1, 12);
- scoreRight = getRandomInt(1, 12);
- a = whoShouldServe(scoreLeft, scoreRight, 2);
- Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a);
- assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2));
- scoreLeft = getRandomInt(1, 12);
- scoreRight = getRandomInt(1, 12);
- a = whoShouldServe(scoreLeft, scoreRight, 2);
- Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a);
- assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2));
- scoreLeft = getRandomInt(1, 12);
- scoreRight = getRandomInt(1, 12);
- a = whoShouldServe(scoreLeft, scoreRight, 2);
- Test.assertEquals(a, whoIs(scoreLeft, scoreRight, 2), "expected: " + whoIs(scoreLeft, scoreRight, 2) + " got: " + a);
- assert.strictEqual(a, whoIs(scoreLeft, scoreRight, 2));
- });
- });
add_PATH() { echo -n "$PATH:$1" | awk 'BEGIN{RS=":";ORS=""}!x[$0]++{if(SEP){print ":"}print $0;SEP=1}' } echo "Original Path: $PATH" export PATH=$(add_PATH /usr/local/bin2) echo "New Path: $PATH"
- add_PATH() {
t=$(echo $PATH | tr : '\n' | awk '!x[$0]++' | tr '\n' : | sed 's/.$//')echo -n "$t"unset t- echo -n "$PATH:$1" | awk 'BEGIN{RS=":";ORS=""}!x[$0]++{if(SEP){print ":"}print $0;SEP=1}'
- }
- echo "Original Path: $PATH"
export PATH=$(add_PATH /usr/local/bin)echo "New Path: $PATH"- export PATH=$(add_PATH /usr/local/bin2)
- echo "New Path: $PATH"
This solution uses a simple hash for holding stringified args to quickly lookup the cache.
The assumption is that only one type of function signature is ever used.
describe("Solution", function(){ var called = 0; function sum(a, b) { called++; return a + b; } it("should add 1 + 2", function(){ Test.assertEquals(memoize(sum)(1,2), 3); }); it("should have been called once", function(){ Test.assertEquals(called, 1); }); it("should still have been called once due to cache", function(){ memoize(sum)(1,2) Test.assertEquals(called, 1); }); it("should still have been called twice if different param orders", function(){ memoize(sum)(2,1) Test.assertEquals(called, 2); }); });
- describe("Solution", function(){
- var called = 0;
- function sum(a, b) {
- called++;
- return a + b;
- }
- it("should add 1 + 2", function(){
- Test.assertEquals(memoize(sum)(1,2), 3);
- });
- it("should have been called once", function(){
- Test.assertEquals(called, 1);
- });
- it("should still have been called once due to cache", function(){
- memoize(sum)(1,2)
- Test.assertEquals(called, 1);
- });
- it("should still have been called twice if different param orders", function(){
- memoize(sum)(2,1)
- Test.assertEquals(called, 2);
- });
- });
using System.Numerics; public class basic { public static BigInteger pow(long down, ulong up) { BigInteger output = 1; BigInteger cumulativeDown = down; for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1) { if((bitChecker & up) != 0) { output *= cumulativeDown; } cumulativeDown *= cumulativeDown; } return output; } }
- using System.Numerics;
- public class basic
- {
public static BigInteger pow(long down, long up)=> up == 0 ? 1 : down * pow(down, up - 1);- public static BigInteger pow(long down, ulong up)
- {
- BigInteger output = 1;
- BigInteger cumulativeDown = down;
- for(ulong bitChecker = 1; bitChecker > 0 && bitChecker <= up; bitChecker <<= 1)
- {
- if((bitChecker & up) != 0)
- {
- output *= cumulativeDown;
- }
- cumulativeDown *= cumulativeDown;
- }
- return output;
- }
- }
import java.util.stream.*; class Solution { public static String largestNumber(final Integer[] nums) { return Stream.of(nums) .sorted((a,b)->(""+b+a).compareTo(""+a+b)) .collect(Collectors.reducing("",(x)->""+x,String::concat)); } }
- import java.util.stream.*;
- class Solution {
- public static String largestNumber(final Integer[] nums) {
- return Stream.of(nums)
- .sorted((a,b)->(""+b+a).compareTo(""+a+b))
.map(n->""+n).collect(Collectors.joining());- .collect(Collectors.reducing("",(x)->""+x,String::concat));
- }
- }