Created
December 26, 2017 14:16
-
-
Save mjuszczak/d2563217863720bcfc8ca663353dd6d0 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
require 'bigdecimal' | |
switch = true | |
wins = 0 | |
1000.times do |k| | |
doors = [false, false, false] | |
doors[rand 3] = true | |
selection = rand 3 | |
host_door = nil | |
while !host_door || doors[host_door] == true || host_door == selection do | |
host_door = rand 3 | |
end | |
print "Round #{k} #{doors.inspect}: You selected #{selection}. Host opened #{host_door}. " | |
selection = ([0, 1, 2] - [host_door, selection])[0] if switch == true | |
if doors[selection] == true | |
wins += 1 | |
puts "You Win!" | |
else | |
puts "You Lose!" | |
end | |
end | |
puts "Total Percent: #{wins / 1000.00}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment