Begin a new Kumite
Search
About
  • Filter by Language:
  • 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.

let rec times (s : string) n = match n with | 1 -> s | _ -> s + times s (n - 1)

printfn "%s" (times "*" 5)
printfn "%s" (times "he " 5)
wichuFailed Tests

Factorial

let rec factorial = function | 0 -> 1 | n -> factorial(n - 1) * n

printfn "%i" (factorial 0)
printfn "%i" (factorial 1)
printfn "%i" (factorial 2)
printfn "%i" (factorial 3)
printfn "%i" (factorial 4)
printfn "%i" (factorial 5)
printfn "%i" (factorial 6)

rev function (rec)

let rec reverse xs =
    match xs with
    | [] -> xs
    | head :: tail -> reverse tail @ [head]

printfn "%A" (reverse [1;2;3;4;5])
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")
wichuvs.wichuFailed Tests

F# Basics

Code
Diff
  • let add a b = a + b
    
    let square x = x * x
    
    printfn "%i" (add 1 2 |> add 3 |> add 4 |> square)
  • 11
    let add a b = a + b
    
    2+
    22
    let square x = x * x
    
    3
    let result = add 1 2 |> add 3 |> add 4 |> square
    
    44
    5
    printfn result
    
    5+
    printfn "%i" (add 1 2 |> add 3 |> add 4 |> square)
    

Recent Moves:

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

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])
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
let rec sumMult i k n = if i + k < n then i + sumMult (i + k) k n else i

let sumOfMultiples list n = list |> List.map(fun x -> sumMult 0 x n) |> List.sum

printfn "%A" (sumOfMultiples [1; 2; 3] 10)