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.
find a creative way to return .. THE MEANING OF LIFE
your function meaning_of_life_is() should return something to explain the meaning of life.
'something' can be a string, a char, an int, or any other stuff that we may push to output stream... to get the answer!!
constexpr int fact(int n) { if (n < 2) return 1; return n * fact(n-1); } const int HOURS_IN_A_DAY = 24; const int MINUTES_IN_AN_HOUR = 60; const int SECONDS_IN_A_MINUTE = 60; constexpr int seconds_in_a_day() { return HOURS_IN_A_DAY * MINUTES_IN_AN_HOUR * SECONDS_IN_A_MINUTE; }; auto meaning_of_life_is() { return fact(10)/seconds_in_a_day(); }
def meaning_of_life_is():return """go crazy with your imagination and return anything you like.strings, numbers, ... just don't return None.may the most creative answer win"""- constexpr int fact(int n) {
- if (n < 2) return 1;
- return n * fact(n-1);
- }
- const int HOURS_IN_A_DAY = 24;
- const int MINUTES_IN_AN_HOUR = 60;
- const int SECONDS_IN_A_MINUTE = 60;
- constexpr int seconds_in_a_day() { return HOURS_IN_A_DAY * MINUTES_IN_AN_HOUR * SECONDS_IN_A_MINUTE; };
- auto meaning_of_life_is() {
- return fact(10)/seconds_in_a_day();
- }
// TODO: Replace examples and use TDD by writing your own tests Describe(your_solution_to_the_meaning_of_life) { It(your_meaning_of_life_revealed) { std::cout << meaning_of_life_is() << "\n"; } };
import codewars_test as test# TODO Write testsfrom solution import meaning_of_life_is # or from solution import example- // TODO: Replace examples and use TDD by writing your own tests
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_not_equals(meaning_of_life_is(), None)- Describe(your_solution_to_the_meaning_of_life)
- {
- It(your_meaning_of_life_revealed)
- {
- std::cout << meaning_of_life_is() << "\n";
- }
- };
verify_sum=lambda a,b:sum(map(ord,a))==sum(map(ord,b))if a and b else None
class Kata{public static String verifySum(String nameOne, String nameTwo) {int[] sumOfNames = new int[]{0, 0};if (nameOne == null || nameTwo == null) {return "NULL";}for (int i = 0; i < nameOne.length(); i++){sumOfNames[0] += nameOne.charAt(i);}for (int i = 0; i < nameTwo.length(); i++){sumOfNames[1] += nameTwo.charAt(i);}return sumOfNames[0] == sumOfNames[1] ? "TRUE" : "FALSE";}}- verify_sum=lambda a,b:sum(map(ord,a))==sum(map(ord,b))if a and b else None
import codewars_test as test from solution import verify_sum @test.describe('verify_sum') def fixed_tests(): @test.describe('Basic Tests') def one(): test.assert_equals(verify_sum("Sebastian", "Patricia"), False) test.assert_equals(verify_sum("Anna", "Nana"), True) test.assert_equals(verify_sum("Jon", None), None)
import org.junit.Test;import static org.junit.Assert.assertEquals;import org.junit.runners.JUnit4;- import codewars_test as test
- from solution import verify_sum
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.describe('verify_sum')
- def fixed_tests():
- @test.describe('Basic Tests')
- def one():
- test.assert_equals(verify_sum("Sebastian", "Patricia"), False)
- test.assert_equals(verify_sum("Anna", "Nana"), True)
- test.assert_equals(verify_sum("Jon", None), None)
def numberprint(x): l1 = [str(i) for i in range(1, x + 1)] l2 = [str(i) for i in range(x - 1, 0, -1)] l1 += l2 return int("".join(l1))
- def numberprint(x):
nor = 0final = ''while nor < x:nor += 1final += str(nor)while nor > 1:nor -= 1final += str(nor)return int(final)- l1 = [str(i) for i in range(1, x + 1)]
- l2 = [str(i) for i in range(x - 1, 0, -1)]
- l1 += l2
- return int("".join(l1))
def prime_checker(n): if n in [2, 3, 5]: return True elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0: return False a = int(n ** 0.5 / 30) b = [7, 11, 13, 17, 19, 23, 29, 31] for i in [30 * j for j in range(a + 1)]: if True in [n % (i + q) == 0 for q in b if i + q is not n]: return False return True
"""https://en.wikipedia.org/wiki/Primality_testThis one has lesser tests or usage of % operator.An alternative using primality mod 30 = 2 * 3 * 5 instead of 6 = 2 * 3"""- def prime_checker(n):
- if n in [2, 3, 5]:
- return True
- elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
- return False
- a = int(n ** 0.5 / 30)
- b = [7, 11, 13, 17, 19, 23, 29, 31]
- for i in [30 * j for j in range(a + 1)]:
- if True in [n % (i + q) == 0 for q in b if i + q is not n]:
- return False
- return True
from __future__ import annotations from collections import Counter def sort_values(vals:list[int]) -> list[int]: #Given an array of size N containing only 0s, 1s, and 2s; #sort the array in ascending order. assert set(vals) <= {0,1,2} return counting_sort(vals) # O(n+k) instead of n log(n) def counting_sort(vals:list[T]) -> list[T]: res = [] c = Counter(vals) for k,amt in sorted(c.items()): res += [k]*amt return res
- from __future__ import annotations
- from collections import Counter
- def sort_values(vals:list[int]) -> list[int]:
- #Given an array of size N containing only 0s, 1s, and 2s;
- #sort the array in ascending order.
- assert set(vals) <= {0,1,2}
- return counting_sort(vals)
- # O(n+k) instead of n log(n)
- def counting_sort(vals:list[T]) -> list[T]:
- res = []
- c = Counter(vals)
- for k,amt in sorted(c.items()):
- res += [k]*amt
- return res
const code = String.raw` Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) ) True = \ t f . t False = \ t f . f Succ = \ n s z . s (n s z) Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x Minus = \ m n . n Pred m Times = \ m n s . m (n s) isZero = \ n . n (\_.False) True isNotZero = \ n . n (\_.True) False And = \ x y . x y x Or = \ x . x x GT = \ x y . isNotZero (Minus x y) Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m) # function isPrime(n) { # const trial = function trial(i) { # return i * i > n || n % i != 0 && trial(i+1) ; # } ; # return n > 1 && trial(2) ; # } isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) ) ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) ) `
- const code = String.raw`
succ = \ n f x . f (n f x)pair = \a.\b.\c.c a bfst = \pair.pair (\a.\_.a)snd = \pair.pair (\_.\b.b)plus = \pair.\f.\x.(fst pair) f ((snd pair) f x)next = \prev.pair (snd prev) (plus prev)fibonacci = \n. fst (n next (pair (\_.\b.b) (succ (\_.\b.b))))`- Y = \ f . ( \ x . f (x x) ) ( \ x . f (x x) )
- True = \ t f . t
- False = \ t f . f
- Succ = \ n s z . s (n s z)
- Pred = \ n s z . n ( \ f g . g (f s) ) (\_.z) \x.x
- Minus = \ m n . n Pred m
- Times = \ m n s . m (n s)
- isZero = \ n . n (\_.False) True
- isNotZero = \ n . n (\_.True) False
- And = \ x y . x y x
- Or = \ x . x x
- GT = \ x y . isNotZero (Minus x y)
- Mod = \ n m . ( \ r . isZero (Minus m r) 0 r ) (( \ n m . ( \ d . isZero d n (Mod d m) ) (Minus n m) ) n m)
// Stress testing -- "LetRec", "BinaryScott"// Testing implementation of a "String" - ie. Arrays and related functionsconst stress = String.raw`# boolsid = \ x . xtrue = \ a b . afalse = \ a b . bnot = \ b . b false trueand = \ a b . a b falseor = \ a b . a true bxor = \ a b . a (b false true) b- # function isPrime(n) {
- # const trial = function trial(i) {
- # return i * i > n || n % i != 0 && trial(i+1) ;
- # } ;
- # return n > 1 && trial(2) ;
- # }
# ints -- z = endbit, f = offbit, t = onbitzero = \ z _ _ . zsucc = \ n _ f t . n (t zero) t (\ m . f (succ m))bool = \ n . n false (\ _ . true) (\ _ . true)pred = \ n z f t . n z (\ m . t (pred m)) (\ m . bool m (f m) z)odd = \ n . n false false trueeven = \ n . not (odd n)mul2 = \ n _ f _ . f naddSlow = \ a b . bool b (addSlow (succ a) (pred b)) asubSlow = \ a b . bool a (bool b (subSlow (pred a) (pred b)) a) (zero)# arrays as foldr (strings)- isPrime = \ n . ( \ trial . And (GT n 1) (trial 2) )
- ( Y \ trial i . Or (GT (Times i i) n) (And (isNotZero (Mod n i)) (trial (Succ i))) )
- `
const chai = require("chai"); const assert = chai.assert; chai.config.truncateThreshold = 0; // const LC = require("LC"); const LC = { compile: () => compile(code), config } // Temporary. Would normally import, see line above. LC.config.purity = "LetRec"; LC.config.numEncoding = "Church"; const solution = LC.compile(); const {isPrime} = solution; describe("Sample Tests", function() { it("Basics", function() { assert.equal(isPrime(0) (true)(false), false); assert.equal(isPrime(1) (true)(false), false); assert.equal(isPrime(2) (true)(false), true); assert.equal(isPrime(3) (true)(false), true); assert.equal(isPrime(4) (true)(false), false); assert.equal(isPrime(5) (true)(false), true); assert.equal(isPrime(6) (true)(false), false); assert.equal(isPrime(7) (true)(false), true); assert.equal(isPrime(8) (true)(false), false); assert.equal(isPrime(9) (true)(false), false); assert.equal(isPrime(10) (true)(false), false); assert.equal(isPrime(11) (true)(false), true); assert.equal(isPrime(12) (true)(false), false); assert.equal(isPrime(13) (true)(false), true); assert.equal(isPrime(14) (true)(false), false); assert.equal(isPrime(15) (true)(false), false); assert.equal(isPrime(16) (true)(false), false); assert.equal(isPrime(17) (true)(false), true); assert.equal(isPrime(18) (true)(false), false); assert.equal(isPrime(19) (true)(false), true); }); });
- const chai = require("chai");
- const assert = chai.assert;
- chai.config.truncateThreshold = 0;
- // const LC = require("LC");
const LC = { compile: () => compile(code), config: options } // Temporary. Would normally import, see line above.- const LC = { compile: () => compile(code), config } // Temporary. Would normally import, see line above.
- LC.config.purity = "LetRec";
- LC.config.numEncoding = "Church";
- const solution = LC.compile();
const fibonacci = solution.fibonacci;// const subSlow = solution.subSlow; // Uses BinaryScott- const {isPrime} = solution;
- describe("Sample Tests", function() {
- it("Basics", function() {
assert.equal(fibonacci(0), 0);assert.equal(fibonacci(1), 1);assert.equal(fibonacci(2), 1);assert.equal(fibonacci(3), 2);assert.equal(fibonacci(4), 3);assert.equal(fibonacci(5), 5);assert.equal(fibonacci(6), 8);assert.equal(fibonacci(7), 13);assert.equal(fibonacci(20), 6765);// assert.equal(fibonacci(20), 6764);// assert.equal(subSlow(355)(56), 299)- assert.equal(isPrime(0) (true)(false), false);
- assert.equal(isPrime(1) (true)(false), false);
- assert.equal(isPrime(2) (true)(false), true);
- assert.equal(isPrime(3) (true)(false), true);
- assert.equal(isPrime(4) (true)(false), false);
- assert.equal(isPrime(5) (true)(false), true);
- assert.equal(isPrime(6) (true)(false), false);
- assert.equal(isPrime(7) (true)(false), true);
- assert.equal(isPrime(8) (true)(false), false);
- assert.equal(isPrime(9) (true)(false), false);
- assert.equal(isPrime(10) (true)(false), false);
- assert.equal(isPrime(11) (true)(false), true);
- assert.equal(isPrime(12) (true)(false), false);
- assert.equal(isPrime(13) (true)(false), true);
- assert.equal(isPrime(14) (true)(false), false);
- assert.equal(isPrime(15) (true)(false), false);
- assert.equal(isPrime(16) (true)(false), false);
- assert.equal(isPrime(17) (true)(false), true);
- assert.equal(isPrime(18) (true)(false), false);
- assert.equal(isPrime(19) (true)(false), true);
- });
- });