Monty Hall problem: Difference between revisions

→‎{{header|REXX}}: added a second version. -- ~~~~
(Add solution in Io.)
(→‎{{header|REXX}}: added a second version. -- ~~~~)
Line 2,660:
 
=={{header|REXX}}==
===version 1===
{{trans|Java}}
<lang rexx>/* REXX ***************************************************************
Line 2,705 ⟶ 2,706:
Staying wins 332665 times.
NetRexx: 2.042000 seconds
</pre>
 
===version 2===
<lang rexx>/*REXX program simulates a # of trials of the classic Monty Hall problem*/
parse arg t .; if t=='' then t=1000000 /*Not specified? Then use default*/
wins.=0 /*wins.0=stay; wins.1=switching.*/
 
do t /*perform this loop T times. */
door.=0 /*set all doors to zero. */
car=random(1,3); door.car=1 /*TV show hides a car randomly. */
?=random(1,3) ; _=door.? /*contestant picks a random door.*/
wins._=wins._+1 /*bump the type of win strategy. */
end /*DO t*/
 
say 'switching wins ' format(wins.0/t*100,,1)"% of the time."
say ' staying wins ' format(wins.1/t*100,,1)"% of the time."; say
say 'performed' t "times." /*stick a fork in it, we're done.*</lang>
'''output''' when using the default number of trials &nbsp; (one million):
<pre>
switching wins 66.7% of the time.
staying wins 33.3% of the time.
 
performed 1000000 times.
</pre>