Friday, 9 November 2007

Wait Wait.... Another Version of TDD F# Bowling Game

No sooner I post I reflect on the code again and see that there's some hangovers from my orginal mucking around


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:

Harris said...

hehehe... I just found something cool...

(fun x y -> x + y)
can be replaced with just
(+)

Keith said...

even better!