Skip to content

Instantly share code, notes, and snippets.

@mjuszczak
Created December 26, 2017 14:16
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 mjuszczak/d2563217863720bcfc8ca663353dd6d0 to your computer and use it in GitHub Desktop.
Save mjuszczak/d2563217863720bcfc8ca663353dd6d0 to your computer and use it in GitHub Desktop.
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