Last active
November 11, 2017 12:14
-
-
Save iporsut/7d1c6010f373b3afad4eccef5f385364 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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