Skip to content

Instantly share code, notes, and snippets.

@hc5
Created March 22, 2013 06:32
Show Gist options
  • Save hc5/5219410 to your computer and use it in GitHub Desktop.
Save hc5/5219410 to your computer and use it in GitHub Desktop.
import random
count = 0.0
for i in range(10000):
state = 0
while True:
count += 1
if state == 1:
break
r = random.random()
if state == 0:
if r < 0.5:
state = 0
continue
if r < 0.75:
state = 1
continue
if r <= 1:
state = 2
continue
else:
if r < 0.5:
state = 1
continue
else:
state = 2
continue
count /= 10000.0
print "%f" % count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment