Skip to content

Instantly share code, notes, and snippets.

@iamed2
Created Nov 1, 2021
Embed
What would you like to do?
Calculate the experimental odds of snake eyes if you're told "at least one of them is a one"
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