Created
April 24, 2015 02:13
-
-
Save matthewfl/ea0282e9b5bb19917c8f to your computer and use it in GitHub Desktop.
This file contains 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
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