let score_bowls bowls =
let rec score_bowls' frame l =
let nextframe = score_bowls' (frame+1)
match l with
| _ when frame = 11 -> 0
| [10;s] -> 10 + s + s
| 10 :: s :: n :: tail -> 10 + s + n + nextframe (s :: n :: tail )
| f :: s :: n :: tail -> f + s + (if((f+s)=10) then n else 0) + nextframe (n :: tail)
| _ -> List.fold_right (fun x y -> x + y) l 0
score_bowls' 1 bowls

2 comments:
hehehe... I just found something cool...
(fun x y -> x + y)
can be replaced with just
(+)
even better!
Post a Comment