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
Parsing
Algorithms
Logic
Strings
Monads
Data Structures
Functional Programming

http://www.willamette.edu/~fruehr/haskell/seuss.html

A parser for a thing
Is a function from a string
To a list of pairs
Of things and strings!

This monadic parser is missing many basic functions and several important typeclass instances.

{-# LANGUAGE DeriveFunctor, TupleSections #-}
module MonadicParsing where

newtype Parser a = Parser { runParser :: String -> [(a, String)] }
    deriving Functor
    
instance Monad Parser where
    return a = Parser $ return . (a,)
    Parser p >>= f = Parser $ \s -> concatMap (uncurry (runParser.f)) $ p s
wichuFailed Tests

F# Basics 2

let addOne = fun x -> x + 1

let value = addOne <| 1 |> addOne

printfn "%i" value
let rec print list = 
    match list with
    | [] -> ()
    | head::rest -> head |> printfn "%O"; print(rest)

print [1; 5; 7]
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")