RosettaCodeData/Task/Monty-Hall-problem/Phix/monty-hall-problem.phix
2016-12-05 23:44:36 +01:00

15 lines
490 B
Text

integer swapWins = 0, stayWins = 0, winner, choice, reveal, other
atom t0 = time()
for game=1 to 1_000_000 do
winner = rand(3)
choice = rand(3)
while 1 do
reveal = rand(3)
if reveal!=winner and reveal!=choice then exit end if
end while
stayWins += (choice==winner)
other = 6-choice-reveal -- (as 1+2+3=6, and reveal!=choice)
swapWins += (other==winner)
end for
printf(1, "Stay: %,d\nSwap: %,d\nTime: %3.2fs\n",{stayWins,swapWins,time()-t0})