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.
from math import sqrt def is_prime(n): return n > 1 and all(n % i for i in range(2, int(sqrt(n))+1))
import math- from math import sqrt
- def is_prime(n):
if n % 2 == 0 and n > 2:return Falsefor i in range(3, int(math.sqrt(n)) + 1, 2):if n % i == 0:return Falsereturn True- return n > 1 and all(n % i for i in range(2, int(sqrt(n))+1))
# write a add function that doesn't use the plus symbol def add(a, b) a - -b end # Make sure to view the test cases to see how this test now passes
- # write a add function that doesn't use the plus symbol
- def add(a, b)
a + b- a - -b
- end
# Make sure to view the test cases to see how this test fails- # Make sure to view the test cases to see how this test now passes
solution = File.open('/home/codewarrior/solution.txt', 'r').read describe "Check Solution" do it "should prevent the '+' symbol from being used anywhere in the code" do puts solution Test.expect(solution.exclude?('+'), "Your code isn't allowed to include the + symbol!") end it "should still perform addition nonetheless" do Test.assert_equals add(1, 1), 2, "One plus one should equal two" Test.assert_equals add(5, 4), 9 Test.assert_equals add(45, 987), 1032 Test.assert_not_equals add(5, 3), 2, "Your method should do addition and not subtraction" end end
- solution = File.open('/home/codewarrior/solution.txt', 'r').read
- describe "Check Solution" do
- it "should prevent the '+' symbol from being used anywhere in the code" do
- puts solution
- Test.expect(solution.exclude?('+'), "Your code isn't allowed to include the + symbol!")
- end
- it "should still perform addition nonetheless" do
- Test.assert_equals add(1, 1), 2, "One plus one should equal two"
- Test.assert_equals add(5, 4), 9
- Test.assert_equals add(45, 987), 1032
- Test.assert_not_equals add(5, 3), 2, "Your method should do addition and not subtraction"
- end
- end
import numpy as np # calculate the distance between two points in 2d,3d ... nD def distanceND(pA, pB, nD = None): return np.linalg.norm(np.array(pA) - np.array(pB)) distance2D = distanceND distance3D =distanceND
from math import sqrt, pow- import numpy as np
- # calculate the distance between two points in 2d,3d ... nD
- def distanceND(pA, pB, nD = None):
return sqrt(sum(pow(a-b,2) for a,b in zip(pA,pB)))- return np.linalg.norm(np.array(pA) - np.array(pB))
- distance2D = distanceND
- distance3D =distanceND
from math import sqrt def distance2D_check(pA, pB): if pA == pB: return 0 xA, yA = tuple(pA); xB, yB = tuple(pB) return sqrt((xA - xB)**2 + (yA - yB)**2) def distance3D_check(pA, pB): if pA == pB: return 0 xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB) return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2) def assertFuzzyEquals(actual, expected, msg=""): merr = 1e-10 inrange = abs(actual - expected) <= merr if (inrange == False): msg = "At 1e-10: Expected value must be {:.10f} but got {:.10f}" msg = msg.format(expected, actual) return Test.expect(inrange, msg) test.describe("Basic Tests for 2D") pA = [1, 1]; pB = [2, 2] assertFuzzyEquals(distance2D(pA, pB), 1.41421356237) pA = [0, 0]; pB = [5, 6] assertFuzzyEquals(distance2D(pA, pB), 7.81024967591) pA = [-5, 4]; pB = [-10, 6] assertFuzzyEquals(distance2D(pA, pB), 5.38516480713) pA = [-5.1, 4.0]; pB = [10.2, -6.3] assertFuzzyEquals(distance2D(pA, pB), 18.4439692041) test.describe("Basic Tests for 3D") pA = [1, 1, 1]; pB = [2, 2, 2] assertFuzzyEquals(distance3D(pA, pB), 1.73205080757) pA = [0, 0, 0]; pB = [7, 8, 9] assertFuzzyEquals(distance3D(pA, pB), 13.9283882772) pA = [-5, 4, 7]; pB = [-10, 6, -18] assertFuzzyEquals(distance3D(pA, pB), 25.5734237051) pA = [-5.1, 4.0, 1]; pB = [10.2, -6.3, -1] assertFuzzyEquals(distance3D(pA, pB), 18.5520888312) test.describe("Random Tests for 2D") test.describe("Integer coordinates") import random from random import randint for h in range(20): pA = [randint(-100, 100), randint(-100, 100)] pB = [randint(-100, 100), randint(-100, 100)] result = distance2D_check(pA, pB) res = distance2D(pA, pB) assertFuzzyEquals(res, result) test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result)) test.describe("Random Tests for 2D") test.describe("Decimal coordinates") for h in range(20): pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ] pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random()] result = distance2D_check(pA, pB) res = distance2D(pA, pB) assertFuzzyEquals(res, result) test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result)) test.describe("Random Tests for 3D") test.describe("Integer coordinates") for h in range(20): pA = [randint(-100, 100), randint(-100, 100), randint(-100, 100)] pB = [randint(-100, 100), randint(-100, 100), randint(-100, 100)] result = distance3D_check(pA, pB) res = distance3D(pA, pB) assertFuzzyEquals(res, result) test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result)) test.describe("Random Tests for 3D") test.describe("Decimal coordinates") for h in range(10): pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ] pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random(), randint(-100, 100) + random.random()] result = distance3D_check(pA, pB) res = distance3D(pA, pB) assertFuzzyEquals(res, result) test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
- from math import sqrt
- def distance2D_check(pA, pB):
- if pA == pB: return 0
- xA, yA = tuple(pA); xB, yB = tuple(pB)
- return sqrt((xA - xB)**2 + (yA - yB)**2)
- def distance3D_check(pA, pB):
- if pA == pB: return 0
- xA, yA, zA = tuple(pA); xB, yB, zB = tuple(pB)
- return sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)
- def assertFuzzyEquals(actual, expected, msg=""):
- merr = 1e-10
- inrange = abs(actual - expected) <= merr
- if (inrange == False):
- msg = "At 1e-10: Expected value must be {:.10f} but got {:.10f}"
- msg = msg.format(expected, actual)
- return Test.expect(inrange, msg)
- test.describe("Basic Tests for 2D")
- pA = [1, 1]; pB = [2, 2]
- assertFuzzyEquals(distance2D(pA, pB), 1.41421356237)
- pA = [0, 0]; pB = [5, 6]
- assertFuzzyEquals(distance2D(pA, pB), 7.81024967591)
- pA = [-5, 4]; pB = [-10, 6]
- assertFuzzyEquals(distance2D(pA, pB), 5.38516480713)
- pA = [-5.1, 4.0]; pB = [10.2, -6.3]
- assertFuzzyEquals(distance2D(pA, pB), 18.4439692041)
- test.describe("Basic Tests for 3D")
- pA = [1, 1, 1]; pB = [2, 2, 2]
- assertFuzzyEquals(distance3D(pA, pB), 1.73205080757)
- pA = [0, 0, 0]; pB = [7, 8, 9]
- assertFuzzyEquals(distance3D(pA, pB), 13.9283882772)
- pA = [-5, 4, 7]; pB = [-10, 6, -18]
- assertFuzzyEquals(distance3D(pA, pB), 25.5734237051)
- pA = [-5.1, 4.0, 1]; pB = [10.2, -6.3, -1]
- assertFuzzyEquals(distance3D(pA, pB), 18.5520888312)
- test.describe("Random Tests for 2D")
- test.describe("Integer coordinates")
- import random
- from random import randint
- for h in range(20):
- pA = [randint(-100, 100), randint(-100, 100)]
- pB = [randint(-100, 100), randint(-100, 100)]
- result = distance2D_check(pA, pB)
- res = distance2D(pA, pB)
- assertFuzzyEquals(res, result)
- test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
- test.describe("Random Tests for 2D")
- test.describe("Decimal coordinates")
- for h in range(20):
- pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ]
- pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random()]
- result = distance2D_check(pA, pB)
- res = distance2D(pA, pB)
- assertFuzzyEquals(res, result)
- test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
- test.describe("Random Tests for 3D")
- test.describe("Integer coordinates")
- for h in range(20):
- pA = [randint(-100, 100), randint(-100, 100), randint(-100, 100)]
- pB = [randint(-100, 100), randint(-100, 100), randint(-100, 100)]
- result = distance3D_check(pA, pB)
- res = distance3D(pA, pB)
- assertFuzzyEquals(res, result)
- test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
- test.describe("Random Tests for 3D")
- test.describe("Decimal coordinates")
- for h in range(10):
- pA = [randint(-100, 100) + random.random(), randint(-100, 100) + random.random(), randint(-100, 100) + random.random() ]
- pB = [randint(-100, 100) + random.random() , randint(-100, 100) + random.random(), randint(-100, 100) + random.random()]
- result = distance3D_check(pA, pB)
- res = distance3D(pA, pB)
- assertFuzzyEquals(res, result)
- test.it("Distance from " + str(pA) + " to " + str(pB) + " : " + str(result))
using System; class Kata { public static string Main(string greeting, string language) { Console.Write("{0}, {1}!\n", greeting, language); return greeting + ", " + language + "!"; } }
- using System;
- class Kata {
public static void Main(string greeting, string language) {Console.WriteLine("{0}, {1}!", greeting, language);- public static string Main(string greeting, string language) {
- Console.Write("{0}, {1}!\n", greeting, language);
- return greeting + ", " + language + "!";
- }
- }
Changed s.ToLower() → s.ToUpperInvariant(), fitting msdn recommended best practices for strings.
using System; using System.Linq; public class Kata { public static int DuplicateCount(string s) => s.ToUpperInvariant() .GroupBy(c => c) .Count(g => g.Skip(1).Any()); }
- using System;
- using System.Linq;
- public class Kata
- {
- public static int DuplicateCount(string s) =>
s.ToLower().GroupBy(c => c).Count(g => g.Skip(1).Any());- s.ToUpperInvariant()
- .GroupBy(c => c)
- .Count(g => g.Skip(1).Any());
- }
module NCR where --Combinations nCr comb:: Integer -> Integer -> Integer comb n r = factorial n `div` (factorial r * factorial (n-r)) where factorial n = foldr (*) 1 [2..n]
- module NCR where
- --Combinations nCr
- comb:: Integer -> Integer -> Integer
comb n r | n/=r = (factorial n) `div` (factorial r * factorial (n-r) )| n==r = (factorial n) `div` (factorial r)factorial n= foldl (*) 1 [1..n]- comb n r = factorial n `div` (factorial r * factorial (n-r))
- where
- factorial n = foldr (*) 1 [2..n]