Skip to content

Instantly share code, notes, and snippets.

@matthewfl
Created April 24, 2015 02:13
Show Gist options
  • Save matthewfl/ea0282e9b5bb19917c8f to your computer and use it in GitHub Desktop.
Save matthewfl/ea0282e9b5bb19917c8f to your computer and use it in GitHub Desktop.
import random
import sys
def run(n=100):
a = 0
c = 0
while a < n:
c += 1
if a % 2 == 0:
d = 1
else:
d = -1
if random.random() > 1/n:
a += d
else:
a -= d
if a < 0:
a = 0
print('n: {} c: {}'.format(n, c))
return c
def main():
run(int(sys.argv[1]))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment