Skip to content

Instantly share code, notes, and snippets.

@lambda-fairy
Created January 14, 2013 02:55
Show Gist options
  • Save lambda-fairy/4527471 to your computer and use it in GitHub Desktop.
Save lambda-fairy/4527471 to your computer and use it in GitHub Desktop.
Monte Carlo simulation of button pushing game
#!/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