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.
Given a number between 0-99999, the function number_to_english, return the same number pass to argument in letters.
Simple task, but the code is a little bit messy :D
convertion = { 0:'zero', 1:'one', 2:'two', 3:'three', 4:'four', 5:'five', 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten', 11:'eleven', 12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifteen', 16:'sixteen', 17:'seventeen', 18:'eighteen', 19:'nineteen', 20:'twenty', 30:'thirty', 40:'forty', 50:'fifty', 60:'sixty', 70:'seventy', 80:'eighty', 90:'ninety' } def convert(num): if not 0 <= num <= 99999: return '' thousand, num = divmod(num, 1000) hundred, num = divmod(num, 100) ten, unit = divmod(num, 10) output = [] if thousand: output += [convert(thousand), 'thousand'] if hundred: output += [convertion[hundred], 'hundred'] if ten == 1: output += [convertion[ten*10 + unit]] else: if ten: output += [convertion[ten*10]] if not output or unit: output += [convertion[unit]] return ' '.join(output) number_to_english = convert
def mil(n):num={'0':'zero','1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'}dec={'10':'ten','11':'eleven','12':'twelve','13':'thirteen','14':'fourteen','15':'fifteen','16':'sixteen','17':'seventeen','18':'eighteen','19':'nineteen'}dec_com={'20':'twenty','30':'thirty','40':'forty','50':'fifty','60':'sixty','70':'seventy','80':'eighty','90':'ninety'}mil="thousand"th=[]n_t=[x for x in n]for i in n_t:if len(n_t)==2:if i!='1' and n_t[1]=='0':th.append(dec_com[i+'0'])th.append(mil)breakelif i=='1':th.append(dec[i+n_t[1]])th.append(mil)breakelse:th.append(dec_com[i+'0'])th.append(num[n_t[1]])th.append(mil)breakelse:th.append(num[i])th.append(mil)return thdef cen(n):num={'0':'zero','1':'one','2':'two','3':'three','4':'four','5':'five','6':'six','7':'seven','8':'eight','9':'nine'}dec={'10':'ten','11':'eleven','12':'twelve','13':'thirteen','14':'fourteen','15':'fifteen','16':'sixteen','17':'seventeen','18':'eighteen','19':'nineteen'}dec_com={'20':'twenty','30':'thirty','40':'forty','50':'fifty','60':'sixty','70':'seventy','80':'eighty','90':'ninety'}cen="hundred"c=[]n_d=[x for x in n]for m in n_d:if n_d[0]!='0':c.append(num[m])c.append(cen)if n_d[1]=='0' and n_d[2]=='0':breakelif n_d[1]=='0' and n_d[2]!='0':c.append(num[n_d[2]])breakelif n_d[1]!='1' and n_d[2]=='0':c.append(dec_com[n_d[1]+'0'])breakelif n_d[1]=='1':c.append(dec[n_d[1]+n_d[2]])breakelse:c.append(dec_com[n_d[1]+'0'])c.append(num[n_d[2]])breakelse:if n_d[1]=='0' and n_d[2]=='0':breakelif n_d[1]=='0' and n_d[2]!='0':c.append(num[n_d[2]])breakelif n_d[1]!='1' and n_d[2]=='0':c.append(dec_com[n_d[1]+'0'])breakelif n_d[1]!='1' and n_d[2]!='0':c.append(dec_com[n_d[1]+'0'])c.append(num[n_d[2]])breakelif n_d[1]=='1':c.append(dec[n_d[1]+n_d[2]])breakreturn cdef number_to_english(n):num={0:'zero',1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine'}dec={10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'fifteen',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen'}dec_com={20:'twenty',30:'thirty',40:'forty',50:'fifty',60:'sixty',70:'seventy',80:'eighty',90:'ninety'}th=[]c=[]m='{0:,}'.format(n)m=m.split(",")try:if n<0 or type(n)==float or n>99999:passelif n<10:c.append(num[n])elif n<20:c.append(dec[n])elif n%10==0 and n<99:c.append(dec_com[n])elif n<99:k=list(str(n))c.append(dec_com[int(k[0]+'0')])c.append(num[int(k[1])])else:c=cen(m[1])th=mil(m[0])except IndexError:if n<0 or type(n)==float or n>99999:passelif n<10:c.append(num[n])elif n<20:c.append(dec[n])elif n%10==0 and n<99:c.append(dec_com[n])elif n<99:k=list(str(n))c.append(dec_com[int(k[0]+'0')])c.append(num[int(k[1])])else:c=cen(m[0])t=[]t.extend(th)t.extend(c)return " ".join(t)- convertion = {
- 0:'zero', 1:'one', 2:'two', 3:'three', 4:'four', 5:'five',
- 6:'six', 7:'seven', 8:'eight', 9:'nine', 10:'ten',
- 11:'eleven', 12:'twelve', 13:'thirteen', 14:'fourteen', 15:'fifteen',
- 16:'sixteen', 17:'seventeen', 18:'eighteen', 19:'nineteen',
- 20:'twenty', 30:'thirty', 40:'forty', 50:'fifty',
- 60:'sixty', 70:'seventy', 80:'eighty', 90:'ninety'
- }
- def convert(num):
- if not 0 <= num <= 99999:
- return ''
- thousand, num = divmod(num, 1000)
- hundred, num = divmod(num, 100)
- ten, unit = divmod(num, 10)
- output = []
- if thousand:
- output += [convert(thousand), 'thousand']
- if hundred:
- output += [convertion[hundred], 'hundred']
- if ten == 1:
- output += [convertion[ten*10 + unit]]
- else:
- if ten:
- output += [convertion[ten*10]]
- if not output or unit:
- output += [convertion[unit]]
- return ' '.join(output)
- number_to_english = convert
Test.describe("Simple test") test.assert_equals(number_to_english(0),'zero') test.assert_equals(number_to_english(9),'nine') test.assert_equals(number_to_english(11),'eleven') test.assert_equals(number_to_english(20),'twenty') test.assert_equals(number_to_english(100),'one hundred') test.assert_equals(number_to_english(12321),'twelve thousand three hundred twenty one') test.assert_equals(number_to_english(99999),'ninety nine thousand nine hundred ninety nine') Test.describe("Not valid case") test.assert_equals(number_to_english(-1),'') test.assert_equals(number_to_english(9999999),'')
- Test.describe("Simple test")
- test.assert_equals(number_to_english(0),'zero')
- test.assert_equals(number_to_english(9),'nine')
- test.assert_equals(number_to_english(11),'eleven')
- test.assert_equals(number_to_english(20),'twenty')
- test.assert_equals(number_to_english(100),'one hundred')
- test.assert_equals(number_to_english(12321),'twelve thousand three hundred twenty one')
- test.assert_equals(number_to_english(99999),'ninety nine thousand nine hundred ninety nine')
- Test.describe("Not valid case")
- test.assert_equals(number_to_english(-1),'')
- test.assert_equals(number_to_english(9999999),'')
namespace Currying { using System; public static class Functions { public static Func<TOut1> Curry<TOut1>(this Func<TOut1> fn) => () => fn(); public static Func<TIn1, TOut2> Curry<TIn1, TOut2>(this Func<TIn1, TOut2> fn) => a => fn(a); public static Func<TIn1, Func<TIn2, TOut3>> Curry<TIn1, TIn2, TOut3>(this Func<TIn1, TIn2, TOut3> fn) => a => b => fn(a, b); public static Func<TIn1, Func<TIn2, Func<TIn3, TOut4>>> Curry<TIn1, TIn2, TIn3, TOut4>(this Func<TIn1, TIn2, TIn3, TOut4> fn) => a => b => c => fn(a, b, c); public static Func<TIn1, Func<TIn2, Func<TIn3, Func<TIn4, TOut5>>>> Curry<TIn1, TIn2, TIn3, TIn4, TOut5>(this Func<TIn1, TIn2, TIn3, TIn4, TOut5> fn) => a => b => c => d => fn(a, b, c, d); public static Func<TIn1, Func<TIn2, Func<TIn3, Func<TIn4, Func<TIn5, TOut6>>>>> Curry<TIn1, TIn2, TIn3, TIn4, TIn5, TOut6>(this Func<TIn1, TIn2, TIn3, TIn4, TIn5, TOut6> fn) => a => b => c => d => e => fn(a, b, c, d, e); } }
var test = new Currying.TestCurrying();test.testSequential();test.testRandom();- namespace Currying {
- using System;
- public static class Functions {
- public static Func<TOut1> Curry<TOut1>(this Func<TOut1> fn) => () => fn();
- public static Func<TIn1, TOut2> Curry<TIn1, TOut2>(this Func<TIn1, TOut2> fn) => a => fn(a);
- public static Func<TIn1, Func<TIn2, TOut3>> Curry<TIn1, TIn2, TOut3>(this Func<TIn1, TIn2, TOut3> fn) => a => b => fn(a, b);
- public static Func<TIn1, Func<TIn2, Func<TIn3, TOut4>>> Curry<TIn1, TIn2, TIn3, TOut4>(this Func<TIn1, TIn2, TIn3, TOut4> fn) => a => b => c => fn(a, b, c);
- public static Func<TIn1, Func<TIn2, Func<TIn3, Func<TIn4, TOut5>>>> Curry<TIn1, TIn2, TIn3, TIn4, TOut5>(this Func<TIn1, TIn2, TIn3, TIn4, TOut5> fn) => a => b => c => d => fn(a, b, c, d);
- public static Func<TIn1, Func<TIn2, Func<TIn3, Func<TIn4, Func<TIn5, TOut6>>>>> Curry<TIn1, TIn2, TIn3, TIn4, TIn5, TOut6>(this Func<TIn1, TIn2, TIn3, TIn4, TIn5, TOut6> fn) => a => b => c => d => e => fn(a, b, c, d, e);
- }
- }
namespace Solution { using NUnit.Framework; using System; using Currying; // TODO: Replace examples and use TDD development by writing your own tests [TestFixture] public class SolutionTest { [Test] public void MyTest() { // arrange Func<int, int, int> Add = (a, b) => a + b; var function = Functions.Curry(Add); var AddTen = function(10); // act var result = function(10)(20); // assert Assert.AreEqual(30, result); } } }
- namespace Solution {
- using NUnit.Framework;
- using System;
- using Currying;
- // TODO: Replace examples and use TDD development by writing your own tests
- [TestFixture]
- public class SolutionTest
- {
- [Test]
- public void MyTest()
- {
- // arrange
- Func<int, int, int> Add = (a, b) => a + b;
- var function = Functions.Curry(Add);
- var AddTen = function(10);
- // act
- var result = function(10)(20);
- // assert
- Assert.AreEqual(30, result);
- }
- }
- }
module Developer def are_you_dev? true end end class Ivan def give_me_beer? true end end class Andy < Ivan end class Vasa < Andy include Developer end class Kolya < Vasa end
- module Developer
- def are_you_dev?
- true
- end
- end
- class Ivan
- def give_me_beer?
- true
- end
- end
- class Andy < Ivan
- end
- class Vasa < Andy
- include Developer
- end
- class Kolya < Vasa
- end
describe "Solution" do it "should test for something" do Test.assert_equals(Kolya.new.give_me_beer?, true) Test.assert_equals(Kolya.new.are_you_dev?, true) end end
- describe "Solution" do
- it "should test for something" do
- Test.assert_equals(Kolya.new.give_me_beer?, true)
- Test.assert_equals(Kolya.new.are_you_dev?, true)
- end
- end
#include <algorithm> #include <math.h> template< class T > void Swap( T& a, T& b ) { std::swap(a, b); }
- #include <algorithm>
- #include <math.h>
- template< class T >
- void Swap( T& a, T& b )
- {
/*a = (reinterpret_cast<long long >(a) + reinterpret_cast<long long >(b));b = (reinterpret_cast<long long >(a) - reinterpret_cast<long long >(b));a = (reinterpret_cast<long long >(a) - reinterpret_cast<long long >(b));*/long long plla = *((long long*) &a);long long pllb = *((long long*) &b);plla = plla + pllb ;pllb = plla - pllb ;plla = plla - pllb ;a =*((T*) &plla);b =*((T*) &pllb);- std::swap(a, b);
- }
using find
breaks execution once it finds one gluten ingredient. same as someone with celiac disease.
function glutenDetector(ingredients){ const gluten = [ "wheat", "wheat flour", "triticale", "barley", "rye", "brewer's yeast", "malt", "wheatberries", "durum", "emmer", "semolina", "spelt", "farina", "farro", "graham", "kamut", "einkorn" ]; return !!ingredients .toLowerCase() .split(" ") .find(i => gluten.indexOf(i) > -1); }
- function glutenDetector(ingredients){
- const gluten = [
- "wheat",
- "wheat flour",
- "triticale",
- "barley",
- "rye",
- "brewer's yeast",
- "malt",
- "wheatberries",
- "durum",
- "emmer",
- "semolina",
- "spelt",
- "farina",
- "farro",
- "graham",
- "kamut",
- "einkorn"
- ];
return gluten.some(g=>ingredients.includes(g.toUpperCase()));- return !!ingredients
- .toLowerCase()
- .split(" ")
- .find(i => gluten.indexOf(i) > -1);
- }
# Method with three named arguments # https://robots.thoughtbot.com/ruby-2-keyword-arguments def c one: "one", two: "tow", three: "three" p "one: %s two: %s three: %s" % [one,two,three] end c # calling without arguments c two: "TWO2" # calling with one argument c two: "2", one: 1111111 # Calling with 2 arguments with no order c(one: 1, two: 2, three: 3) # Passing 3 Named arguments c(two: 22, three: 333, one: 1 ) # Passing 3 Named arguments (mess the order) begin c fore: "4" # calling with wrong argument rescue Exception => e p e.message p e.class end begin #c (fore:"4") # calling with wrong argument # this lead to syntaxix error rescue Exception => e p e.message p e.class end hash = {one: 'One', two: 'Two', three: 'Three'} c hash # calling with hash hash = {two: 'Two', three: 'Three', one: 'One', } c hash # calling with hash mess in order hash = { one: 'One', } c hash # calling with hash where not all argumetns listed # Super syntax hash = { two: '222', } c one: 1, **hash # c one: 1, hash # <== leads to error begin hash = { one: 'One', fore: "4" } c hash # calling with hash that contain pair unlisetd in named arguments rescue Exception => e p e.message p e.class end
- # Method with three named arguments
- # https://robots.thoughtbot.com/ruby-2-keyword-arguments
- def c one: "one", two: "tow", three: "three"
- p "one: %s two: %s three: %s" % [one,two,three]
- end
- c # calling without arguments
- c two: "TWO2" # calling with one argument
- c two: "2", one: 1111111 # Calling with 2 arguments with no order
- c(one: 1, two: 2, three: 3) # Passing 3 Named arguments
- c(two: 22, three: 333, one: 1 ) # Passing 3 Named arguments (mess the order)
- begin
- c fore: "4" # calling with wrong argument
- rescue Exception => e
- p e.message
- p e.class
- end
- begin
- #c (fore:"4") # calling with wrong argument
- # this lead to syntaxix error
- rescue Exception => e
- p e.message
- p e.class
- end
- hash = {one: 'One', two: 'Two', three: 'Three'}
- c hash # calling with hash
- hash = {two: 'Two', three: 'Three', one: 'One', }
- c hash # calling with hash mess in order
- hash = { one: 'One', }
- c hash # calling with hash where not all argumetns listed
- # Super syntax
- hash = { two: '222', }
- c one: 1, **hash
- # c one: 1, hash # <== leads to error
- begin
- hash = { one: 'One', fore: "4" }
- c hash # calling with hash that contain pair unlisetd in named arguments
- rescue Exception => e
- p e.message
- p e.class
- end
const wordCount = s => s.split(/\s/).filter(v=>!!v).length
const wordCount = str => str.split(" ").filter(a=>!!a).length- const wordCount = s => s.split(/\s/).filter(v=>!!v).length
// TODO: Replace examples and use TDD development by writing your own tests // These are some CW specific test methods available: // Test.expect(boolean, [optional] message) // Test.assertEquals(actual, expected, [optional] message) // Test.assertSimilar(actual, expected, [optional] message) // Test.assertNotEquals(actual, expected, [optional] message) // NodeJS assert is also automatically required for you. // assert(true) // assert.strictEqual({a: 1}, {a: 1}) // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]}) // You can also use Chai (http://chaijs.com/) by requiring it yourself // var expect = require("chai").expect; // var assert = require("chai").assert; // require("chai").should(); Test.assertEquals(wordCount(" v"), 1); Test.assertEquals(wordCount("Word"), 1); Test.assertEquals(wordCount("Wo r d"), 3); Test.assertEquals(wordCount("Bob the t-rex"), 3); Test.assertEquals(wordCount("People type the\tweirdest stuff"), 5);
- // TODO: Replace examples and use TDD development by writing your own tests
- // These are some CW specific test methods available:
- // Test.expect(boolean, [optional] message)
- // Test.assertEquals(actual, expected, [optional] message)
- // Test.assertSimilar(actual, expected, [optional] message)
- // Test.assertNotEquals(actual, expected, [optional] message)
- // NodeJS assert is also automatically required for you.
- // assert(true)
- // assert.strictEqual({a: 1}, {a: 1})
- // assert.deepEqual({a: [{b: 1}]}, {a: [{b: 1}]})
- // You can also use Chai (http://chaijs.com/) by requiring it yourself
- // var expect = require("chai").expect;
- // var assert = require("chai").assert;
- // require("chai").should();
- Test.assertEquals(wordCount(" v"), 1);
- Test.assertEquals(wordCount("Word"), 1);
- Test.assertEquals(wordCount("Wo r d"), 3);
- Test.assertEquals(wordCount("Bob the t-rex"), 3);
- Test.assertEquals(wordCount("People type the\tweirdest stuff"), 5);