Skip to content

Instantly share code, notes, and snippets.

@solen003
Created July 15, 2018 12:25
Show Gist options
  • Save solen003/09be3f02b72032c166a41070b44f6318 to your computer and use it in GitHub Desktop.
Save solen003/09be3f02b72032c166a41070b44f6318 to your computer and use it in GitHub Desktop.
import random
def random_walk2(n):
"""n number of blocks to walk"""
x, y = 0, 0
for i in range(1, n):
(dx, dy) = random.choice([(0, 1), (0, -1), (-1, 0), (1, 0)])
x = x + dx
y = y + dy
return(x, y)
for i in range(1, 26):
location = random_walk2(10)
print(i, location, "Distance from home: ", abs(location[0]) + abs(location[1]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment