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

4 comments:

Unknown said...

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

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

Keith said...

even better!

michel said...

I'm becoming more acquainted with it better! Cheers, keep doing awesome!
scape room in Romeoville

Momina Sheikh said...

This particular is usually apparently essential and moreover outstanding truth along with for sure fair-minded and moreover admittedly useful My business is looking to find in advance designed for this specific useful stuffs… New Jersey escape room