Skip to content

Instantly share code, notes, and snippets.

@jpark9013
Created July 1, 2020 03:33
Show Gist options
  • Save jpark9013/27ecd093905d3ceb0e7108dfbe073760 to your computer and use it in GitHub Desktop.
Save jpark9013/27ecd093905d3ceb0e7108dfbe073760 to your computer and use it in GitHub Desktop.
Proving the TED riddle frogs video
# Frogs problem on TED
import random
def run():
bothFrogs = 0
oneFrog = 0
# Doing 100000 trials, bothfrogs probability printed top, one below
for i in range(100000):
# 0 = has the cure, 1 = does not have the cure
# First checking both frogs
frog1 = random.randint(0, 1)
frog2 = random.randint(0, 1)
# Checking if both frogs have the cure (it is confirmed at least one of them do not)
while frog1 == 0 and frog2 == 0:
frog1 = random.randint(0, 1)
frog2 = random.randint(0, 1)
# Checking if one of them has the cure
if frog1 == 0 or frog2 == 0:
bothFrogs += 1
# Now checking for the one frog, reusing variable
frog1 = random.randint(0, 1)
if frog1 == 0:
oneFrog += 1
print(f"{bothFrogs/1000}%")
print(f"{oneFrog/1000}%")
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment