Monty Hall problem: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: modified the code to work with the latest version of Sidef) |
|||
Line 2,482: | Line 2,482: | ||
Staying wins 9% of the time. |
Staying wins 9% of the time. |
||
Switching wins 90% of the time.</pre> |
Switching wins 90% of the time.</pre> |
||
=={{header|Phix}}== |
|||
Modified copy of [[Monty_Hall_problem#Euphoria|Euphoria]] |
|||
<lang Phix>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})</lang> |
|||
{{out}} |
|||
<pre> |
|||
Stay: 333,292 |
|||
Swap: 666,708 |
|||
Time: 0.16s |
|||
</pre> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |