Anonymous user
Monty Hall problem: Difference between revisions
→{{header|REXX}}: changed/added comments and whitespace, changed indentations, removed the original version 2.
(→{{header|REXX}}: changed/added comments and whitespace, changed indentations, removed the original version 2.) |
|||
Line 3,128:
===version 2===
<lang rexx>/*REXX program simulates a number of trials of the classic Monty Hall problem. */▼
if #=='' | #=="," then
if d==''
wins.=0
wins._ = wins._ + 1 /*bump the type of win strategy. */▼
end /*#*/ /* [↑] perform the loop # times. */▼
say 'switching wins ' format(wins.0 / # * 100, , 1)"% of the time."
say ' staying wins ' format(wins.1 / # * 100, , 1)"% of the time." ; say
say 'performed ' # " times
'''output''' when using
<pre>
switching wins 66.
staying wins 33.
performed 1000000 times with 3 doors.
</pre>
'''output''' when using the default number of trials (one million) and with four doors: <tt> , 4 </tt>▼
▲<lang rexx>/*REXX program simulates a number of trials of the classic Monty Hall problem.*/
▲ /*door values: 0≡goat 1≡car */
▲ wins._ = wins._ + 1 /*bump the type of win strategy. */
▲ end /*#*/ /* [↑] perform the loop # times. */
▲'''output''' when using the default number of trials (one million) and with four doors:
<pre>
switching wins 75.0% of the time.
Line 3,173 ⟶ 3,157:
performed 1000000 times with 4 doors.
</pre>
'''output''' when using the default number of trials (one million) and with five doors: <tt> , 5 </tt>
<pre>
switching wins 80.0% of the time.
Line 3,180 ⟶ 3,164:
performed 1000000 times with 5 doors.
</pre>
'''output''' when using the default number of trials (one million) and with six doors: <tt> , 6 </tt>
<pre>
switching wins 83.6% of the time.
|