Created
February 14, 2014 09:08
-
-
Save amiorin/8998014 to your computer and use it in GitHub Desktop.
This file contains 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
# http://codingdojo.org/cgi-bin/wiki.pl?KataBowling | |
# "5/5/5/5/5/5/5/5/5/5/5" | |
rolls = [5 for x in range(21)] | |
# "XXXXXXXXXXXX" | |
rolls = [10 for x in range(12)] | |
# "9-9-9-9-9-9-9-9-9-9-" | |
rolls = zip([9 for x in range(10)], [0 for x in range(10)]) | |
rolls = [e for l in rolls for e in l] | |
def score(rolls, prev=0): | |
if len(rolls) == 3: | |
return sum(rolls) | |
roll = rolls.pop(0) | |
if roll == 10: | |
return roll + sum(rolls[0:2]) + score(rolls) | |
elif roll + prev == 10: | |
return roll + rolls[0] + score(rolls) | |
else: | |
return roll + score(rolls, roll if prev == 0 else 0) | |
print rolls | |
print score(rolls) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment