Created
September 21, 2021 00:40
-
-
Save sebastorama/22d67a100ff1ce36305328ef81f00551 to your computer and use it in GitHub Desktop.
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
MY_BIRTHDAY = 89 | |
SIMULATIONS = 100000 | |
# true if found someone with my birthday | |
def run_test(num_people) | |
((1..num_people).filter do | |
rand(365) == MY_BIRTHDAY | |
end).length > 0 | |
end | |
# ratio between true/falses on the func above | |
def simulate_n_times(num_people) | |
puts "Simulating for #{num_people}" | |
true_false_array = (1..SIMULATIONS).map do | |
run_test(num_people) | |
end | |
answer = true_false_array.filter { |item| item }.length / SIMULATIONS.to_f | |
puts "Answer is ~ #{answer*100}%" | |
end | |
simulate_n_times(182) | |
simulate_n_times(183) | |
simulate_n_times(253) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment