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
Algorithms
Logic

Data.Set is better. It's safer than head/tail and faster than nub (O(n^2)). For instance, size is O(1) and fromList is O(n*log n).

Code
Diff
  • module AllEqual where
    import Data.Set (fromList, size)
    
    allEqual :: [Int] -> Bool 
    allEqual xs = (size $ fromList xs) <= 1
    • module AllEqual where
    • import Data.List
    • import Data.Set (fromList, size)
    • allEqual :: [Int] -> Bool
    • allEqual xs = length (nub xs) <= 1
    • allEqual xs = (size $ fromList xs) <= 1
Code
Diff
  • SELECT * FROM current_catalog
    • SELECT current_database();
    • SELECT * FROM current_catalog
Mathematics
Algorithms
Logic
Numbers
Data Types

You can declare Array with running numbers up by using [...Array(n).keys]. Then if you want it start from 1, you just increase array size then slice it of.

Code
Diff
  • const isPerfect = n => 
      [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n
    • const isPerfect = n =>
    • Array(n - 1).fill(1).map((e, i) => e + i).filter(e => n % e === 0).reduce((a, b) => a + b) === n
    • [...Array(n).keys()].slice(1).filter(e => !(n % e)).reduce((a, b) => a + b) === n
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 
      puts("#{e.message}\n#{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 
      puts("#{e.message}\n#{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
    • puts("#{e.message}\n#{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
    • puts("#{e.message}\n#{e.class}")
    • end
Code
Diff
  • wordCount=s=>s.trim().split` `.length
    • function wordCount(str) {
    • return str.trim().split(" ").length;
    • }
    • wordCount=s=>s.trim().split` `.length

This is a response to the kumite https://www.codewars.com/kumite/5a4edf17d8e145968c00015e to show that it has an elegant solution for ruby using the compiled bash utility "tr"

It's my first kumite so I'm not sure if this is how to use it. Don't mind if I do!

Code
Diff
  • def pattern a,b
      a.tr(a,b)==b && b.tr(b,a)==a
    end
    • def pattern(p,st):
    • def encode(s):
    • dic={} # dictionary to hold values from the input string
    • num=0
    • sn="" # a numerical string to hold the encoding
    • for i in s:
    • if i not in dic:
    • dic[i]=num
    • num+=1
    • sn+=str(dic[i])
    • return sn
    • return encode(st)==encode(p)
    • def pattern a,b
    • a.tr(a,b)==b && b.tr(b,a)==a
    • end
Code
Diff
  • def euler(num):
        return sum([i for i in range(num) if i%3==0 or i%5==0])
    • def euler(num):
    • sum = 0
    • for x in range(num):
    • if x%3==0 or x%5==0:
    • sum += x
    • return sum
    • return sum([i for i in range(num) if i%3==0 or i%5==0])

Reduced, printing only simple stuff.

Code
Diff
  • bool alwaysTrue(int, int, int) {
      return true;
    }
    • template <class... Args>
    • bool alwaysTrue(Args&&...) {
    • bool alwaysTrue(int, int, int) {
    • return true;
    • }