Skip to content

Instantly share code, notes, and snippets.

@cboudereau
Created April 19, 2017 07:17
Show Gist options
  • Save cboudereau/d279f2b2963ae309209a7938a42af687 to your computer and use it in GitHub Desktop.
Save cboudereau/d279f2b2963ae309209a7938a42af687 to your computer and use it in GitHub Desktop.
let score =
let score x y z =
if x = 10 || x + y = 10 then x + y + z
else x + y
List.fold
<| fun s v ->
match v, s with
| z, (r, [x;y]) -> (r + score x y z), [y;z]
| y, (r, x::tail) -> r, x::y::tail
| x, (r, []) -> r, [x]
<| (0, [])
>> fst
let strike = 10
[strike;strike;strike] |> score = 30
[strike;strike;strike;strike] |> score = 60
[strike;strike;strike;strike;strike] |> score = 90
[strike;strike;strike;strike;strike;strike] |> score = 120
[strike;strike;strike;strike;strike;strike;strike] |> score = 150
[for i = 1 to 12 do yield strike] |> score = 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment