3 ms·
I found this on the internet and modified it so you can just change the commented out options to run it under the different scenarios. car = wins = 0 many
by jayvanguard 12y ago
I found this on the internet and modified it so you can just change the commented out options to run it under the different scenarios.
car = wins = 0
many = 100000
actual = 0
many.times do
choice1 = rand(3)
car = rand(3)
#host_opts = [0, 1, 2] - [choice1, car] # host knows what is behind
host_opts = [0, 1, 2] - [choice1] # host doesn't know what is behind
#choice2 = [choice1] # don't switch
choice2 = [0, 1, 2] - [choice1, host_opts.first] # switch
if host_opts.first == car then
# Discard? Automatic win? It doesn't actually matter!
# It only changes the denominator.
else
# According to the puzzle, it is decision time!
wins += 1 if choice2.first == car
actual += 1
end
end
puts "#{(wins * 100) / actual}%"
- skizm 12y ago> if host_opts.first == car then That is false 100% of the time given the parameters that the outcome of the host's choice is a goat (as the question states)
- dllthomas 12y agoYes, and we don't bump the wins or the number of tries for that case. The question is your odds if you switch in the other branch of the if, and that's what we are calculating. Edited to add: I think there may be a different misunderstanding here... Set aside, for the moment, whether the above implements the originally posed question or the variant. Imagine a gameshow that runs the above code, but the switch/stay code is moved below the "decision time!" line and the decision is made based on a prompt rather than hard coded. When you hit that prompt, "Monty" has already picked his door, and we've checked that it's not a car. Do you expect your chance to win, on answering "switch" at that prompt, to depend on which line above is commented out?
- dllthomas 12y agoI believe it doesn't change the result, but this is technically Monty always picking "the lower (leftmost?) door you didn't pick" not "a random door you didn't pick", right? Also, "it only changes the denominator" may be misleading, as it does not change the only denominator actually visible in the code. It changes the total numbers of wins and losses, but not the total numbers of wins and losses given that you saw a goat.
- jayvanguard 12y agoRe: first pick, right it doesn't affect things, but here is the code anyways using Ruby Array.sample(). open_door = host_opts.sample choice2 = [0, 1, 2] - [choice1, open_door] # switch if open_door == car then As for the denominator, good point.