Skip to content

Instantly share code, notes, and snippets.

@JulianNorton
Last active March 31, 2017 14:50
Show Gist options
  • Select an option

  • Save JulianNorton/9b563325a6eea4910554d5a905c6470c to your computer and use it in GitHub Desktop.

Select an option

Save JulianNorton/9b563325a6eea4910554d5a905c6470c to your computer and use it in GitHub Desktop.
Riddler Express 538 20170324
# results https://docs.google.com/spreadsheets/d/1q3YD0AlzynouZmyBJqCWTnxAClhHoagoEGcHH3OncAc/edit?usp=sharing
# This video would have been super helpful to watch BEFORE trying this problem
# https://www.youtube.com/watch?v=stgYW6M5o4k
# SOLUTION!
# https://fivethirtyeight.com/features/what-are-the-chances-well-meet-for-lunch/
# [This program is wrong.]
import random
max_time = 10000
time = 0
baby_map = []
# 4 sided die
def d4():
result = random.randint(1, 4)
# print(result, 'd4 result')
return result
def walk(time, max_time):
# Baby hasn't done anything yet
distance = 0
# Begin the experiment!
while time < max_time:
# What's baby doing?
baby_map.append([time, distance])
time += 1
# If baby is at home couch
if distance == 0:
# 25% of the time, baby moves forward!
if d4() == 1:
distance = distance + 1
baby_map.append([time, distance])
# If baby is not at couch
if distance is not 0:
print(distance)
# one die roll
movement = d4()
# 25% of time baby moves forward
if movement == 1:
distance = distance + 1
# print('moving (+) ->', distance)
# 50% of time baby moves back
elif movement == 2 or 3:
distance = distance - 1
# print('moving (-) ->', distance)
# 25% of time baby stays
elif movement == 4:
pass
# print('im staying put', distance)
walk(time, max_time)
print(baby_map)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment