Monty Hall problem: Difference between revisions

Content added Content deleted
m (→‎version 2: added a comment regarding the door values (goat or car). -- ~~~~)
Line 2,740: Line 2,740:
#the doors reveal 2 goats and a car
#the doors reveal 2 goats and a car
doors = [ :goat , :goat , :goat ]
doors = [ :goat, :goat, :car ].shuffle
doors[rand(3)] = :car
#random guess
#random guess
Line 2,749: Line 2,748:
begin shown = rand(3) end while shown == guess || doors[shown] == :car
begin shown = rand(3) end while shown == guess || doors[shown] == :car
#staying with the initial guess wins if the initial guess is the car
if doors[guess] == :car
stay += 1 if doors[guess] == :car
#staying with the initial guess wins if the initial guess is the car
stay += 1
else
#switching guesses wins if the unshown door is the car
#switching guesses wins if the unshown door is the car
switch += 1 if doors[3-guess-shown] == :car
switch += 1
end
end
end
Line 2,762: Line 2,763:
<pre>Staying wins 33.84% of the time.
<pre>Staying wins 33.84% of the time.
Switching wins 66.16% of the time.</pre>
Switching wins 66.16% of the time.</pre>

=={{header|Run BASIC}}==
=={{header|Run BASIC}}==
<lang runbasic>' adapted from BASIC solution
<lang runbasic>' adapted from BASIC solution