Skip to content

Instantly share code, notes, and snippets.

@deque-blog

deque-blog/score.idr

Last active Jun 15, 2017
Embed
What would you like to do?
score' : Nat -> Vect n Frame -> List Nat -> Nat
score' current [] _ = current
score' current (f :: fs) rolls =
let frameRollNb = length (knockedPins f) -- Nb of rolls in the frame
scoreRollNb = frameRollNb + bonusRolls f -- Nb of rolls to sum
frameScore = sum (take scoreRollNb rolls) -- Sum of the rolls to sum
in score' -- Recur:
(current + frameScore) -- Add the frame score to the current score
fs -- Advance the the next frame
(drop frameRollNb rolls) -- Advance to the next rolls
score : BowlingGame -> Nat
score game@(MkBowlingGame frames bonus) = score' 0 frames (gameRolls game)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.