Skip to content

Instantly share code, notes, and snippets.

@iporsut
Last active November 11, 2017 12:14
Show Gist options
  • Save iporsut/7d1c6010f373b3afad4eccef5f385364 to your computer and use it in GitHub Desktop.
Save iporsut/7d1c6010f373b3afad4eccef5f385364 to your computer and use it in GitHub Desktop.
module Main where
score xs = score' xs 0 0
score' _ acc 10 = acc
score' (10:b1:b2:xs) acc frame = score' (b1:b2:xs) (acc+10+b1+b2) (frame+1)
score' (r1:r2:b1:xs) acc frame | r1 + r2 == 10 = score' (b1:xs) (acc+10+b1) (frame+1)
score' (r1:r2:xs) acc frame = score' xs (acc+r1+r2) (frame+1)
main :: IO ()
main = do
print $ score [10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]
print $ score [9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0, 9, 0]
print $ score [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment