Created
November 1, 2021 16:27
-
-
Save iamed2/f44504c590a77c32839ab7aa5edebf4f to your computer and use it in GitHub Desktop.
Calculate the experimental odds of snake eyes if you're told "at least one of them is a one"
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
function tally(n=100) | |
snake_eyes = 0 | |
any_ones = 0 | |
for i in 1:n | |
rolls = (dice_roll(), dice_roll()) | |
if 1 in rolls # tests at least one of them is a one | |
any_ones += 1 | |
if rolls[1] == rolls[2] # tests both are one | |
snake_eyes += 1 | |
end | |
end | |
end | |
return snake_eyes, any_ones | |
end | |
odds(tally) = tally[1] / tally[2] | |
# will approach 1/11 as you increase the number of trials | |
for trials in [100, 1000, 10000, 100000, 1000000, 10000000, 10000000] | |
println(odds(tally(trials))) | |
end | |
println() | |
println(1/11) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment