Created
July 1, 2020 03:33
-
-
Save jpark9013/27ecd093905d3ceb0e7108dfbe073760 to your computer and use it in GitHub Desktop.
Proving the TED riddle frogs video
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
# 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