Skip to content

Instantly share code, notes, and snippets.

@tormaroe
Created October 29, 2019 20:32
Show Gist options
  • Save tormaroe/764c68173c263e78f947f73cb3c6b377 to your computer and use it in GitHub Desktop.
Save tormaroe/764c68173c263e78f947f73cb3c6b377 to your computer and use it in GitHub Desktop.
comp.lang.fsharp
// Bowling kata
type Spec = { Rolls: int list; Expected: int }
let specs = [
{ Rolls = [0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0]; Expected = 0 }
{ Rolls = [1;2;4;5;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0;0]; Expected = 12 }
{ Rolls = [1;2;4;6;3;4;0;0;0;0;0;0;0;0;0;0;0;0;0;0]; Expected = 23 }
{ Rolls = [5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5;5]; Expected = 150 }
{ Rolls = [1;2;10;3;4;0;0;0;0;0;0;0;0;0;0;0;0;0;0]; Expected = 27 }
{ Rolls = [10;10;10;10;10;10;10;10;10;10;10;10]; Expected = 300 }
{ Rolls = [10;7;3;9;0;10;0;8;8;2;0;6;10;10;10;8;1]; Expected = 167 }
]
let printResult (spec, actual) =
if actual = spec.Expected
then printfn "OK %A = %A" spec.Rolls actual
else printfn "FAIL %A got %A expected %A" spec.Rolls actual spec.Expected
specs
|> List.map (fun s -> s, score s.Rolls)
|> List.iter printResult
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment