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
Fundamentals
public static class Kata
{
    public static int Add(this int a, int b) => a + b;
}
wichuFailed Tests

Even or Odd ?

let (|Even|Odd|) n = if n % 2 = 0 then Even else Odd

let testNum n =
    match n with
    | Even -> printfn "%i is even" n
    | Odd -> printfn "%i is odd" n

testNum 1
testNum 2
testNum 3
testNum 4
testNum 5
wichuFailed Tests

Quicksort

let rec quicksort list =
    match list with
    | [] -> []
    | first::rest -> 
        let smaller,larger = List.partition ((>=) first) rest 
        List.concat [quicksort smaller; [first]; quicksort larger]
        
printfn "%A" (quicksort [3;1;5;4;2])
arr2bin=(arr)->
  if arr.filter( (n)-> !(n%1==0) ).length
    return '0'
  sum = arr.map((x)-> if typeof x =="number" then x else 0).reduce((x,y)->(x+y))
  return sum.toString(2);
wichuFailed Tests

Fizz Buzz

let (|MultOf3|_|) i = if i % 3 = 0 then Some MultOf3 else None
let (|MultOf5|_|) i = if i % 5 = 0 then Some MultOf5 else None

let fizzBuzz i = 
    match i with
    | MultOf3 & MultOf5 -> printfn "FizzBuzz" 
    | MultOf3 -> printfn "Fizz" 
    | MultOf5 -> printfn "Buzz" 
    | _ -> printfn "%i" i
    
    
fizzBuzz 3
fizzBuzz 4
fizzBuzz 5
fizzBuzz 15
wichuFailed Tests

Hello World

printfn "%s" "Hello World"
wichuFailed Tests

Pig Latin

let stringToCharList (s : string) = s.ToCharArray() |> List.ofArray

let charListToString (list : char list) = list |> List.map(fun c -> c.ToString()) |> List.reduce(fun s str -> s + str)

let phraseToWords (phrase : string) = phrase.Split(' ') |> List.ofArray

let wordsToPhrase (words : string list) = words |> List.reduce(fun s str -> s + " " + str)

let translateWord (word : char list) =
    match word with
    | 'a' :: rest
    | 'e' :: rest
    | 'i' :: rest
    | 'o' :: rest
    | 'u' :: rest
    | 'x' :: 'r' :: rest
    | 'y' :: 't' :: rest            -> word @ ['a'; 'y']
    | 'c' :: 'h' :: rest            -> rest @ ['c'; 'h'; 'a'; 'y']
    | 'q' :: 'u' :: rest            -> rest @ ['q'; 'u'; 'a'; 'y']
    |  c  :: 'q' :: 'u' :: rest     -> rest @ [c] @ ['q'; 'u'; 'a'; 'y']
    | 't' :: 'h' :: 'r' :: rest     -> rest @ ['t'; 'h'; 'r'; 'a'; 'y']
    | 't' :: 'h' :: rest            -> rest @ ['t'; 'h'; 'a'; 'y']
    | 's' :: 'c' :: 'h' :: rest     -> rest @ ['s'; 'c'; 'h'; 'a'; 'y']
    |  c  :: rest                   -> rest @ [c] @ ['a'; 'y']
    | _ -> []

let translateWords (words : string list) = words |> List.map(fun word -> word |> stringToCharList |> translateWord |> charListToString)

let translate (phrase : string) = phrase |> phraseToWords |> translateWords |> wordsToPhrase

printfn "%s" (translate "hello world")

Haskell is lazy, so we could get infinite sequence naturally.

like this.

module InfiniteSeq where

import Data.List

ones = repeat 1
nats = [0..]

merge = concat . transpose
merge2 x y = merge [x, y]

ints = 0: merge2 [1..] [(-1),(-2)..]

write one compare function.

  • first compare with string's length
  • when string have same length, then compare string with lex order.
module CmpStr where

import Data.Function
import Data.Monoid

cmpStr :: String -> String -> Ordering
cmpStr = (compare `on` length) `mappend` compare

There seems to be an error with looking at the top of a stack, but it doesn't throw. It just kills execution. What's going on here?

#include <stack>

bool method() 
{
  std::stack<int> my_stack;
  //my_stack.push(1);
  try {
    if(my_stack.top()) 
    {
    }
  }
  catch(...) {
    std::cout << "An Exception Occurred" << std::endl;
  }
  return true;
}