Start a new Kumite
AllAgda (Beta)BF (Beta)CCFML (Beta)ClojureCOBOL (Beta)CoffeeScriptCommonLisp (Beta)CoqC++CrystalC#D (Beta)DartElixirElm (Beta)Erlang (Beta)Factor (Beta)Forth (Beta)Fortran (Beta)F#GoGroovyHaskellHaxe (Beta)Idris (Beta)JavaJavaScriptJulia (Beta)Kotlinλ Calculus (Beta)LeanLuaNASMNim (Beta)Objective-C (Beta)OCaml (Beta)Pascal (Beta)Perl (Beta)PHPPowerShell (Beta)Prolog (Beta)PureScript (Beta)PythonR (Beta)RacketRaku (Beta)Reason (Beta)RISC-V (Beta)RubyRustScalaShellSolidity (Beta)SQLSwiftTypeScriptVB (Beta)
Show only mine

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.

Ad
Ad

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

Code
Diff
  • 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)
    • break
    • elif i=='1':
    • th.append(dec[i+n_t[1]])
    • th.append(mil)
    • break
    • else:
    • th.append(dec_com[i+'0'])
    • th.append(num[n_t[1]])
    • th.append(mil)
    • break
    • else:
    • th.append(num[i])
    • th.append(mil)
    • return th
    • def 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':
    • break
    • elif n_d[1]=='0' and n_d[2]!='0':
    • c.append(num[n_d[2]])
    • break
    • elif n_d[1]!='1' and n_d[2]=='0':
    • c.append(dec_com[n_d[1]+'0'])
    • break
    • elif n_d[1]=='1':
    • c.append(dec[n_d[1]+n_d[2]])
    • break
    • else:
    • c.append(dec_com[n_d[1]+'0'])
    • c.append(num[n_d[2]])
    • break
    • else:
    • if n_d[1]=='0' and n_d[2]=='0':
    • break
    • elif n_d[1]=='0' and n_d[2]!='0':
    • c.append(num[n_d[2]])
    • break
    • elif n_d[1]!='1' and n_d[2]=='0':
    • c.append(dec_com[n_d[1]+'0'])
    • break
    • elif n_d[1]!='1' and n_d[2]!='0':
    • c.append(dec_com[n_d[1]+'0'])
    • c.append(num[n_d[2]])
    • break
    • elif n_d[1]=='1':
    • c.append(dec[n_d[1]+n_d[2]])
    • break
    • return c
    • def 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:
    • pass
    • elif 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:
    • pass
    • elif 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
Code
Diff
  • 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);
    • }
    • }
Code
Diff
  • 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
Code
Diff
  • #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.

Code
Diff
  • 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);
    • }
Code
Diff
  • # 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
Code
Diff
  • 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