Skip to content

Instantly share code, notes, and snippets.

@vilmibm
Created February 10, 2016 00:55
Show Gist options
  • Save vilmibm/76c59caf78409a83e472 to your computer and use it in GitHub Desktop.
Save vilmibm/76c59caf78409a83e472 to your computer and use it in GitHub Desktop.
from random import randint
def d6():
return randint(1,6)
def explode():
print("explosion!")
next_roll = d6()
final = next_roll + 6
while next_roll == 6:
print("explosion!")
next_roll = d6()
final += next_roll
return final
def roll(die, tn):
results = []
for roll in range(die):
result = d6()
if result == 6:
result = explode()
results.append(result)
print(results)
if len(list(filter(lambda r: r == 1, results))) == len(results):
return "catastrophic failure D:"
elif len(list(filter(lambda r: r >= tn, results))) > 0:
return "success :D"
else:
return "failure :("
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment