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.
package main import "fmt" func main() { var age int fmt.Printf("Enter your age on Earth: ") _, err := fmt.Scanf("%d", &age) if (err != nil) { fmt.Println(err) } age = age * 365 / 687 fmt.Printf("Your age on the surface of Mars is %d years old.\n", age) }
- package main
- import "fmt"
- func main() {
age := 28 * 365 / 687fmt.Printf("My age on the surface of Mars is %d years old.", age)- var age int
- fmt.Printf("Enter your age on Earth: ")
- _, err := fmt.Scanf("%d", &age)
- if (err != nil) {
- fmt.Println(err)
- }
- age = age * 365 / 687
- fmt.Printf("Your age on the surface of Mars is %d years old.
- ", age)
- }
const countLetterInSentence = (sentence, letter) => ([...sentence].filter(test => letter === test).length) function countLettersInSentence(sentence, letters){ return letters.map(letter => countLetterInSentence(sentence, letter)) }
function testAmount(sentence, letters){return letters.map(letter =>[...sentence].filter(test => letter === test).length)- const countLetterInSentence = (sentence, letter) => ([...sentence].filter(test => letter === test).length)
- function countLettersInSentence(sentence, letters){
- return letters.map(letter => countLetterInSentence(sentence, letter))
- }
describe("Should return how many of a certain letter is in a sentence", function(){ it("should test for the amount of letters in the given letters", function(){ Test.assertSimilar( countLettersInSentence("a long sentence of random things about the sentences",["a","o"]), [3, 4] ); Test.assertSimilar( countLettersInSentence("a long sentence of random things about the sentences",["a","k"]), [3, 0] ); }); });
- describe("Should return how many of a certain letter is in a sentence", function(){
- it("should test for the amount of letters in the given letters", function(){
- Test.assertSimilar(
testAmount("a long sentence of random things about the sentences",["a","o"]), [3, 4]- countLettersInSentence("a long sentence of random things about the sentences",["a","o"]), [3, 4]
- );
- Test.assertSimilar(
testAmount("a long sentence of random things about the sentences",["a","k"]), [3, 0]- countLettersInSentence("a long sentence of random things about the sentences",["a","k"]), [3, 0]
- );
- });
- });
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()); }
- using System;
- using System.Linq;
- public class Kata
- {
public static int DuplicateCount(string str){return str.ToLower().GroupBy(c => c).Count (g => g.Count () > 1);}- public static int DuplicateCount(string s) =>
- s.ToLower()
- .GroupBy(c => c)
- .Count(g => g.Skip(1).Any());
- }
using NUnit.Framework; public class DuplicateCount { [Test] public void ShouldReturnZeroWhenEmptyString() => Assert.That(Kata.DuplicateCount(""), Is.EqualTo(0)); [TestCase("a", 0)] [TestCase("ab", 0)] [TestCase("abcde", 0)] [TestCase("ABC", 0)] public void ShouldReturnZeroWhenNoDuplicates(string s, int expected) => Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected)); [TestCase("aa", 1)] [TestCase("bb", 1)] [TestCase("abb", 1)] [TestCase("AAB", 1)] public void ShouldHandleSingleDuplicateCharacter(string s, int expected) => Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected)); [TestCase("aabb", 2)] [TestCase("aabbcde", 2)] [TestCase("abbcdde", 2)] [TestCase("AABCC", 2)] public void ShouldHandleMultipleDuplicates(string s, int expected) => Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected)); [TestCase("aba", 1)] [TestCase("abcb", 1)] [TestCase("abab", 2)] [TestCase("ABCABC", 3)] public void ShouldHandleNonAdjacentCharacters(string s, int expected) => Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected)); [TestCase("aA", 1)] [TestCase("aABb", 2)] [TestCase("aabBcde", 2)] [TestCase("aBcdE", 0)] public void ShouldIgnoreCase(string s, int expected) => Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected)); [Test] public void ShouldCountSingleDuplicateOnce() => Assert.That(Kata.DuplicateCount("Indivisibility"), Is.EqualTo(1), "Indivisibility"); [Test] public void ShouldCountMultipleDuplicatesOncePerCharacter() => Assert.That(Kata.DuplicateCount("Indivisibilities"), Is.EqualTo(2), "Indivisibilities"); }
namespace Solution {using System;using System.Text.RegularExpressions;using System.Collections.Generic;using System.Linq;using NUnit.Framework;[TestFixture]public class KataTest{- using NUnit.Framework;
- public class DuplicateCount
- {
- [Test]
- public void ShouldReturnZeroWhenEmptyString() =>
- Assert.That(Kata.DuplicateCount(""), Is.EqualTo(0));
- [TestCase("a", 0)]
- [TestCase("ab", 0)]
- [TestCase("abcde", 0)]
- [TestCase("ABC", 0)]
- public void ShouldReturnZeroWhenNoDuplicates(string s, int expected) =>
- Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected));
- [TestCase("aa", 1)]
- [TestCase("bb", 1)]
- [TestCase("abb", 1)]
- [TestCase("AAB", 1)]
- public void ShouldHandleSingleDuplicateCharacter(string s, int expected) =>
- Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected));
- [TestCase("aabb", 2)]
- [TestCase("aabbcde", 2)]
- [TestCase("abbcdde", 2)]
- [TestCase("AABCC", 2)]
- public void ShouldHandleMultipleDuplicates(string s, int expected) =>
- Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected));
- [TestCase("aba", 1)]
- [TestCase("abcb", 1)]
- [TestCase("abab", 2)]
- [TestCase("ABCABC", 3)]
- public void ShouldHandleNonAdjacentCharacters(string s, int expected) =>
- Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected));
- [TestCase("aA", 1)]
- [TestCase("aABb", 2)]
- [TestCase("aabBcde", 2)]
- [TestCase("aBcdE", 0)]
- public void ShouldIgnoreCase(string s, int expected) =>
- Assert.That(Kata.DuplicateCount(s), Is.EqualTo(expected));
- [Test]
- public void ShouldCountSingleDuplicateOnce() =>
- Assert.That(Kata.DuplicateCount("Indivisibility"), Is.EqualTo(1), "Indivisibility");
- [Test]
public void KataTests(){Assert.AreEqual(0, Kata.DuplicateCount(""));Assert.AreEqual(0, Kata.DuplicateCount("abcde"));Assert.AreEqual(2, Kata.DuplicateCount("aabbcde"));Assert.AreEqual(0, Kata.DuplicateCount("a"));Assert.AreEqual(1, Kata.DuplicateCount("aa"));Assert.AreEqual(2, Kata.DuplicateCount("aabBcde"), "should ignore case");Assert.AreEqual(1, Kata.DuplicateCount("Indivisibility"));Assert.AreEqual(2, Kata.DuplicateCount("Indivisibilities"), "characters may not be adjacent");}}- public void ShouldCountMultipleDuplicatesOncePerCharacter() =>
- Assert.That(Kata.DuplicateCount("Indivisibilities"), Is.EqualTo(2), "Indivisibilities");
- }
Why only 2D and 3D? The universe may contain any number of dimensions! Most popular teories say there are around 6.
Since we are not sure of how many, lets use as backend a function that will work for any number of dimensions: distanceND.
from math import sqrt, pow # calculate the distance between two points in 2d,3d ... nD def distanceND(pA, pB, nD = None): dist = 0 # if a number of dimension was not specified, use the smalest number of dimensions if nD is None: nD = min(len(pA),len(pB)) for i in range(nD): dist += pow(pA[i] - pB[i], 2); return(sqrt(dist)); def distance2D(pA, pB): return(distanceND(pA, pB)) def distance3D(pA, pB): return(distanceND(pA, pB))
from math import sqrt- from math import sqrt, pow
- # calculate the distance between two points in 2d,3d ... nD
- def distanceND(pA, pB, nD = None):
- dist = 0
- # if a number of dimension was not specified, use the smalest number of dimensions
- if nD is None:
- nD = min(len(pA),len(pB))
- for i in range(nD):
- dist += pow(pA[i] - pB[i], 2);
- return(sqrt(dist));
- def distance2D(pA, pB):
if pA == pB: return 0(xA, yA), (xB, yB) = pA, pBreturn sqrt((xA - xB)**2 + (yA - yB)**2)- return(distanceND(pA, pB))
- def distance3D(pA, pB):
if pA == pB: return 0(xA, yA, zA), (xB, yB, zB) = pA, pBreturn sqrt((xA - xB)**2 + (yA - yB)**2 + (zA - zB) **2)- return(distanceND(pA, pB))
function isPrime(n) { if (n < 2) return false; // do an early exit for even numbers if (n == 2) return true; if (n % 2 == 0) return false; // we only have to check odd numbers, starting with 3 for (var x = 3; x <= Math.floor(Math.sqrt(n)); x += 2) if (n % x == 0) return false; return true; }
- function isPrime(n) {
if (n < 2) return false;for (var x = 2; x <= Math.floor(Math.sqrt(n)); x++) {if (n % x == 0) return false;}- if (n < 2)
- return false;
- // do an early exit for even numbers
- if (n == 2)
- return true;
- if (n % 2 == 0)
- return false;
- // we only have to check odd numbers, starting with 3
- for (var x = 3; x <= Math.floor(Math.sqrt(n)); x += 2)
- if (n % x == 0)
- return false;
- return true;
- }
import random def rabinMiller(num): s = num - 1 t = 0 while s % 2 == 0: s = s // 2 t += 1 for trials in range(5): a = random.randrange(2, num - 1) v = pow(a, s, num) if v != 1: i = 0 while v != (num - 1): if i == t - 1: return False else: i = i + 1 v = (v ** 2) % num return True def is_prime(num): if (num < 2): return False lowPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997] if num in lowPrimes: return True for prime in lowPrimes: if (num % prime == 0): return False return rabinMiller(num)
- import random
def decompose(n):exponentOfTwo = 0while n % 2 == 0:n = n/2exponentOfTwo += 1return exponentOfTwo, ndef isWitness(possibleWitness, p, exponent, remainder):possibleWitness = pow(possibleWitness, remainder, p)if possibleWitness == 1 or possibleWitness == p - 1:return Falsefor _ in range(exponent):possibleWitness = pow(possibleWitness, 2, p)if possibleWitness == p - 1:return False- def rabinMiller(num):
- s = num - 1
- t = 0
- while s % 2 == 0:
- s = s // 2
- t += 1
- for trials in range(5):
- a = random.randrange(2, num - 1)
- v = pow(a, s, num)
- if v != 1:
- i = 0
- while v != (num - 1):
- if i == t - 1:
- return False
- else:
- i = i + 1
- v = (v ** 2) % num
- return True
def is_prime(p, accuracy=100):if p == 2 or p == 3: return Trueif p < 2: return Falseexponent, remainder = decompose(p - 1)for _ in range(accuracy):possibleWitness = random.randint(2, p - 2)if isWitness(possibleWitness, p, exponent, remainder):- def is_prime(num):
- if (num < 2):
- return False
- lowPrimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997]
- if num in lowPrimes:
- return True
- for prime in lowPrimes:
- if (num % prime == 0):
- return False
return True- return rabinMiller(num)