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.
Validate Windows 95 CD Key
A similar solution in Python.
Sorry about changing the format of the test cases, I copied the format from another Kumite because I don't know how to do it otherwise.
def validateKey(key): segments = key.split('-') illegalSites = ["333", "444", "555", "666", "777", "888", "999"] illegalEnds = ["0", "8", "9"] return len(segments) == 2 and len(segments[0]) == 3 and len(segments[1]) == 7 and not segments[0] in illegalSites and not segments[1][-1:] in illegalEnds
function validateKey(key) {var segments = key.split('-');- def validateKey(key):
- segments = key.split('-')
var illegalSites = [333, 444, 555, 666, 777, 888, 999];var illegalEnds = [0, 8, 9];- illegalSites = ["333", "444", "555", "666", "777", "888", "999"]
- illegalEnds = ["0", "8", "9"]
if (segments.length != 2|| illegalSites.includes(+(segments[0])) || +(segments[0]) > 999 || +(segments[0]) < 0 || segments[0].length != 3|| +(segments[1]) % 7 == true || illegalEnds.includes(+(segments[1].slice(-1))) || segments[1].length != 7) {return false}return true;}- return len(segments) == 2 and len(segments[0]) == 3 and len(segments[1]) == 7 and not segments[0] in illegalSites and not segments[1][-1:] in illegalEnds
# TODO: Add your tests here # Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework. # [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework) # are still available for now. # # For new tests, using [Chai](https://chaijs.com/) is recommended. # You can use it by requiring: # const assert = require("chai").assert; # If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted. import unittest class MyTest(unittest.TestCase): def test0(self): self.assertEqual(validateKey('879-5676524'), True); def test1(self): self.assertEqual(validateKey('879-5676529'), False); def test2(self): self.assertEqual(validateKey('535-5676524'), True); def test3(self): self.assertEqual(validateKey('000-5676524'), True); def test4(self): self.assertEqual(validateKey('999-5676524'), False); def test5(self): self.assertEqual(validateKey('764-2365839'), False); def test6(self): self.assertEqual(validateKey('3-5676524'), False); def test7(self): self.assertEqual(validateKey('364-17688'), False); def test8(self): self.assertEqual(validateKey('5676524'), False); def test9(self): self.assertEqual(validateKey('3-'), False); if __name__ == '__main__': unittest.main()
// TODO: Add your tests here// Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.// [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)// are still available for now.//// For new tests, using [Chai](https://chaijs.com/) is recommended.// You can use it by requiring:// const assert = require("chai").assert;// If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.- # TODO: Add your tests here
- # Starting from Node 10.x, [Mocha](https://mochajs.org) is used instead of our custom test framework.
- # [Codewars' assertion methods](https://github.com/Codewars/codewars.com/wiki/Codewars-JavaScript-Test-Framework)
- # are still available for now.
- #
- # For new tests, using [Chai](https://chaijs.com/) is recommended.
- # You can use it by requiring:
- # const assert = require("chai").assert;
- # If the failure output for deep equality is truncated, `chai.config.truncateThreshold` can be adjusted.
- import unittest
describe("Solution", function() {it("validate keys", function() {Test.assertEquals(validateKey('879-5676524'), true);Test.assertEquals(validateKey('879-5676529'), false);Test.assertEquals(validateKey('535-5676524'), true);Test.assertEquals(validateKey('000-5676524'), true);Test.assertEquals(validateKey('999-5676524'), false);Test.assertEquals(validateKey('764-2365839'), false);Test.assertEquals(validateKey('3-5676524'), false);Test.assertEquals(validateKey('364-17688'), false);Test.assertEquals(validateKey('5676524'), false);Test.assertEquals(validateKey('3-'), false);});});- class MyTest(unittest.TestCase):
- def test0(self):
- self.assertEqual(validateKey('879-5676524'), True);
- def test1(self):
- self.assertEqual(validateKey('879-5676529'), False);
- def test2(self):
- self.assertEqual(validateKey('535-5676524'), True);
- def test3(self):
- self.assertEqual(validateKey('000-5676524'), True);
- def test4(self):
- self.assertEqual(validateKey('999-5676524'), False);
- def test5(self):
- self.assertEqual(validateKey('764-2365839'), False);
- def test6(self):
- self.assertEqual(validateKey('3-5676524'), False);
- def test7(self):
- self.assertEqual(validateKey('364-17688'), False);
- def test8(self):
- self.assertEqual(validateKey('5676524'), False);
- def test9(self):
- self.assertEqual(validateKey('3-'), False);
- if __name__ == '__main__':
- unittest.main()
Sum of Two Numbers
Recursion makes everything more elegant, right?
...right?
import numpy def add(x, y): if x == 0 and y == 0: return 0 elif y == 0: return add(x - numpy.sign(x), 0) + numpy.sign(x) else: return add(x, y - numpy.sign(y)) + numpy.sign(y)
from math import ceil, log10, sqrt- import numpy
- def add(x, y):
return ceil(10 ** log10(ceil(sqrt(x**2 + 2*x*y + y**2))))- if x == 0 and y == 0:
- return 0
- elif y == 0:
- return add(x - numpy.sign(x), 0) + numpy.sign(x)
- else:
- return add(x, y - numpy.sign(y)) + numpy.sign(y)
import unittest class MyTest(unittest.TestCase): def test0(self): self.assertEqual(add(3,4), 7) def test1(self): self.assertEqual(add(5,5), 10) def test2(self): self.assertEqual(add(9,9), 18) def test3(self): self.assertEqual(add(-9,-9), -18) def test4(self): self.assertEqual(add(-9,9), 0) def test5(self): self.assertEqual(add(9,-9), 0) if __name__ == '__main__': unittest.main()
- import unittest
- class MyTest(unittest.TestCase):
- def test0(self):
- self.assertEqual(add(3,4), 7)
- def test1(self):
- self.assertEqual(add(5,5), 10)
- def test2(self):
- self.assertEqual(add(9,9), 18)
- def test3(self):
- self.assertEqual(add(-9,-9), -18)
- def test4(self):
- self.assertEqual(add(-9,9), 0)
- def test5(self):
- self.assertEqual(add(9,-9), 0)
- if __name__ == '__main__':
- unittest.main()
using FactCheck facts("Tests") do powerdistance(2) --> 3 powerdistance(3) --> 5 powerdistance(4) --> 7 powerdistance(5) --> 9 powerdistance(6) --> 11 powerdistance(7) --> 13 end
test.assert_equals(power_distance(2), 3)test.assert_equals(power_distance(3), 5)test.assert_equals(power_distance(4), 7)test.assert_equals(power_distance(5), 9)test.assert_equals(power_distance(6), 11)test.assert_equals(power_distance(7), 13)- using FactCheck
- facts("Tests") do
- @fact powerdistance(2) --> 3
- @fact powerdistance(3) --> 5
- @fact powerdistance(4) --> 7
- @fact powerdistance(5) --> 9
- @fact powerdistance(6) --> 11
- @fact powerdistance(7) --> 13
- end