Skip to content

Instantly share code, notes, and snippets.

@amiorin
Created February 14, 2014 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amiorin/8998014 to your computer and use it in GitHub Desktop.
Save amiorin/8998014 to your computer and use it in GitHub Desktop.
# 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