Last active
August 29, 2015 14:00
-
-
Save Grepsy/4bf77a88e06ab7ec7e52 to your computer and use it in GitHub Desktop.
Bowling Kata - F#, try 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let games = [ | |
(0, [0; 0 ]); | |
(5, [0; 5 ]); | |
(10, [5; 5; 0; 0 ]); | |
(20, [5; 5; 5; 0 ]); | |
(10, [10; 0; 0 ]); | |
(20, [10; 5; 0 ]); | |
(20, [10; 0; 5 ]); | |
(30, [10; 5; 5 ]); | |
(300, [10; 10; 10; 10; 10; 10; 10; 10; 10; 10; 10; 10 ]) | |
] | |
let rec score rolls frame = | |
let nextFrame = frame + 1 | |
let bonus count xs = (xs |> Seq.truncate count |> Seq.sum) | |
match rolls with | |
| _ when frame > 10 -> 0 | |
| 10::xs -> 10 + bonus 2 xs + score xs nextFrame | |
| a::b::xs when a + b = 10 -> 10 + bonus 1 xs + score xs nextFrame | |
| a::xs -> a + score xs nextFrame | |
| [] -> 0 | |
let test (expected, game) = | |
printfn "%A" (expected, score game 1) | |
List.map test games |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment