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.
def basicOp(operation, value1, value2): if operation == "+": return value1 + value2 if operation == "-": return value1 - value2 if operation == "*": return value1 * value2 if operation == "/": return value1 / value2 return "Invalid Operation"
function basicOp(operation, value1, value2) {switch (operation) {case '+':return value1 + value2;case '-':return value1 - value2;case '*':return value1 * value2;case '/':return value1 / value2;default:return 0;//Suppose we're adding 1 and -1.}}- def basicOp(operation, value1, value2):
- if operation == "+":
- return value1 + value2
- if operation == "-":
- return value1 - value2
- if operation == "*":
- return value1 * value2
- if operation == "/":
- return value1 / value2
- return "Invalid Operation"
Test.describe("Basic Tests") test.assert_equals(basicOp("-", 2, 1), 1) test.assert_equals(basicOp("+", 3, 3), 6) test.assert_equals(basicOp("/", 8, 2), 4) test.assert_equals(basicOp("*", 4, 5), 20) test.assert_equals(basicOp("@", 6, 3), "Invalid Operation") Test.describe("Complex Tests") test.assert_equals(basicOp("-", -12, 9), -21) test.assert_equals(basicOp("+", 23, 17), 40) test.assert_equals(basicOp("/", 111, 37), 3) test.assert_equals(basicOp("-", 230, 133), 97) test.assert_equals(basicOp("*", 42, 63), 2646)
// 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.- Test.describe("Basic Tests")
- test.assert_equals(basicOp("-", 2, 1), 1)
- test.assert_equals(basicOp("+", 3, 3), 6)
- test.assert_equals(basicOp("/", 8, 2), 4)
- test.assert_equals(basicOp("*", 4, 5), 20)
- test.assert_equals(basicOp("@", 6, 3), "Invalid Operation")
describe("Solution", function() {it("should test for something", function() {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);});});- Test.describe("Complex Tests")
- test.assert_equals(basicOp("-", -12, 9), -21)
- test.assert_equals(basicOp("+", 23, 17), 40)
- test.assert_equals(basicOp("/", 111, 37), 3)
- test.assert_equals(basicOp("-", 230, 133), 97)
- test.assert_equals(basicOp("*", 42, 63), 2646)
def verifySum(w1, w2) return false if w1.nil? || w2.nil? w1.downcase().split('').map(&:ord).inject(:+) == w2.downcase().split('').map(&:ord).inject(:+) end
class Kata{public static String verifySum(String nameOne, String nameTwo) {if (nameOne == null || nameTwo == null) return "NULL";else return nameOne.chars().sum() == nameTwo.chars().sum() ? "TRUE" : "FALSE";}}- def verifySum(w1, w2)
- return false if w1.nil? || w2.nil?
- w1.downcase().split('').map(&:ord).inject(:+) == w2.downcase().split('').map(&:ord).inject(:+)
- end
Test.assert_equals(verifySum('Sebastian', 'Patricia'), false); Test.assert_equals(verifySum('Anna', 'Nana'), true); Test.assert_equals(verifySum('John', nil), false);
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;public class SolutionTest {@Testpublic void testName() {assertEquals("FALSE", Kata.verifySum("Sebastian", "Patricia"));assertEquals("TRUE", Kata.verifySum("Anna", "Nana"));assertEquals("NULL", Kata.verifySum("John", null));}}- Test.assert_equals(verifySum('Sebastian', 'Patricia'), false);
- Test.assert_equals(verifySum('Anna', 'Nana'), true);
- Test.assert_equals(verifySum('John', nil), false);
namespace Solution { using NUnit.Framework; using System; [TestFixture] public class SolutionTest { [Test] public void MyTest() { Sum sum = new Sum(); Assert.AreEqual(19, sum.GetSum(9, 10)); Assert.AreEqual(21, sum.GetSum(11, 10)); Assert.AreEqual(4294967292, sum.GetSum(2147483646, 2147483646)); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void MyTest()
- {
- Sum sum = new Sum();
- Assert.AreEqual(19, sum.GetSum(9, 10));
Assert.AreEqual(21, sum.GetSum(11, 10));- Assert.AreEqual(21, sum.GetSum(11, 10));
- Assert.AreEqual(4294967292, sum.GetSum(2147483646, 2147483646));
- }
- }
- }
def factorise(a): # takes much less than O(a), unless a is prime prime_factors = {} p = 1 while a > 1: p += 1 while a % p == 0: if p in prime_factors: prime_factors[p] += 1 else: prime_factors[p] = 1 a = a//p return prime_factors def totient(a): """python 3.6.0""" primes = factorise(a) totient = 1 for i in primes: # formula for totient from prime factorisation totient *= i**(primes[i]-1) * (i-1) return totient
from math import gcd- def factorise(a): # takes much less than O(a), unless a is prime
- prime_factors = {}
- p = 1
- while a > 1:
- p += 1
- while a % p == 0:
- if p in prime_factors: prime_factors[p] += 1
- else: prime_factors[p] = 1
- a = a//p
- return prime_factors
- def totient(a):
- """python 3.6.0"""
return len([b for b in range(a) if (gcd(a, b) == 1)])- primes = factorise(a)
- totient = 1
- for i in primes: # formula for totient from prime factorisation
- totient *= i**(primes[i]-1) * (i-1)
- return totient
test.assert_equals(totient(1), 1) test.assert_equals(totient(2), 1) test.assert_equals(totient(3), 2) test.assert_equals(totient(4), 2) test.assert_equals(totient(5), 4) test.assert_equals(totient(6), 2) test.assert_equals(totient(7), 6) test.assert_equals(totient(8), 4) test.assert_equals(totient(9), 6) test.assert_equals(totient(128), 64) test.assert_equals(totient(127), 126) test.assert_equals(totient(1001), 720)
- test.assert_equals(totient(1), 1)
- test.assert_equals(totient(2), 1)
- test.assert_equals(totient(3), 2)
- test.assert_equals(totient(4), 2)
- test.assert_equals(totient(5), 4)
- test.assert_equals(totient(6), 2)
- test.assert_equals(totient(7), 6)
- test.assert_equals(totient(8), 4)
test.assert_equals(totient(9), 6)- test.assert_equals(totient(9), 6)
- test.assert_equals(totient(128), 64)
- test.assert_equals(totient(127), 126)
- test.assert_equals(totient(1001), 720)