Last active
September 14, 2024 10:43
Revisions
-
sirupsen revised this gist
Sep 13, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ switch_strategy = 0 no_switch_strategy = 0 n_simulations = 1_000_000 n_simulations.times do winner_door = rand(3) @@ -21,3 +21,5 @@ puts "Switch strategy wins: #{switch_strategy} (#{(switch_strategy.to_f / n_simulations * 100).round(2)}%}" puts "No Switch strategy wins: #{no_switch_strategy} (#{(no_switch_strategy.to_f / n_simulations * 100).round(2)}%)" # Switch strategy wins: 666481 (66.65%} # No Switch strategy wins: 333519 (33.35%) -
sirupsen created this gist
Sep 13, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,23 @@ switch_strategy = 0 no_switch_strategy = 0 n_simulations = 100_000 n_simulations.times do winner_door = rand(3) chosen_door = rand(3) if winner_door == chosen_door switch_strategy += 0 no_switch_strategy += 1 else # The host always opens the other non-winning door and not your door, this # reveals 'information' about your door. revealed_door = [0, 1, 3] - [winner_door] - [chosen_door] chosen_door = winner_door switch_strategy += 1 no_switch_strategy += 0 end end puts "Switch strategy wins: #{switch_strategy} (#{(switch_strategy.to_f / n_simulations * 100).round(2)}%}" puts "No Switch strategy wins: #{no_switch_strategy} (#{(no_switch_strategy.to_f / n_simulations * 100).round(2)}%)"