Monty Hall problem: Difference between revisions

(Added a solution in Ruby)
Line 1,027:
#random guess
shown = guess = rand(3)
#random door shown, but it is neither the guess nor the 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
Line 1,040:
end
 
printfputs "Staying wins %.2f%s% of the time.\n" ,% (100.0 * stay / n , '%')
printfputs "Switching wins %.2f%s% of the time.\n" ,% (100.0 * switch / n , '%')</lang>
Sample Output:
<pre>Staying wins 33.84% of the time.
Anonymous user