Skip to content

Instantly share code, notes, and snippets.

@iamed2
Created November 1, 2021 16:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iamed2/f44504c590a77c32839ab7aa5edebf4f to your computer and use it in GitHub Desktop.
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"
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