Jump to content

Monty Hall problem: Difference between revisions

m (→‎version 2: added a comment regarding the door values (goat or car). -- ~~~~)
Line 2,740:
#the doors reveal 2 goats and a car
doors = [ :goat , :goat , :goatcar ].shuffle
doors[rand(3)] = :car
#random guess
Line 2,749 ⟶ 2,748:
begin shown = rand(3) end while shown == guess || doors[shown] == :car
#staying with the initial guess wins if the initial doors[guess] is the== :car
stay += 1#staying with the initial guess wins if doors[the initial guess] ==is the :car
stay += 1
else
#switching guesses wins if the unshown door is the car
switch += 1 if doors[3-guess-shown] == :car
switch += 1
end
end
Line 2,762 ⟶ 2,763:
<pre>Staying wins 33.84% of the time.
Switching wins 66.16% of the time.</pre>
 
=={{header|Run BASIC}}==
<lang runbasic>' adapted from BASIC solution
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.