Skip to content

Instantly share code, notes, and snippets.

@paulerickson
Created August 30, 2009 18:28
Show Gist options
  • Save paulerickson/178068 to your computer and use it in GitHub Desktop.
Save paulerickson/178068 to your computer and use it in GitHub Desktop.
import random
def stumble(size):
x = int(size / 2)
y = int(size / 2)
count = 0
while -1 < x < size and -1 < y < size:
x += random.randint(-1, 1)
y += random.randint(-1, 1)
count += 1
return count
def average(list):
return sum(list) / len(list)
for size in range(1, 50):
print("Size ", size, ": ", average([stumble(size) for x in range(1000)]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment