Created
October 8, 2023 09:09
-
-
Save hovsater/0f62e80d61a246484072ce40adc50395 to your computer and use it in GitHub Desktop.
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 score game = | |
let rec aux sum frame = | |
function | |
| 10 :: 10 :: [ x ] when frame = 10 && x <= 10 -> Some(sum + 20 + x) | |
| 10 :: x :: [ y ] when frame = 10 && x + y <= 10 -> Some(sum + 10 + x + y) | |
| x :: y :: [ z ] when frame = 10 && x + y = 10 && z <= 10 -> Some(sum + 10 + z) | |
| x :: [ y ] when frame = 10 && x + y < 10 -> Some(sum + x + y) | |
| 10 :: x :: y :: rest -> aux (sum + 10 + x + y) (frame + 1) (x :: y :: rest) | |
| x :: y :: z :: rest when x + y = 10 && z <= 10 -> aux (sum + 10 + z) (frame + 1) (z :: rest) | |
| x :: y :: rest when x + y < 10 -> aux (sum + x + y) (frame + 1) rest | |
| _ -> None | |
aux 0 1 (List.rev game) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment