Created
January 14, 2013 02:55
-
-
Save lambda-fairy/4527471 to your computer and use it in GitHub Desktop.
Monte Carlo simulation of button pushing game
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
#!/usr/bin/env python | |
from random import randint | |
def simulate(): | |
"""Simulate one round of the game Gus described.""" | |
pushes = 1 | |
# Until a kitten pops out | |
while randint(0, 99) != 0: | |
# Push the button | |
pushes += 1 | |
return pushes | |
iterations = 10000 | |
print(sum(simulate() for i in range(iterations)) / float(iterations)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment