Anonymous user
Monty Hall problem: Difference between revisions
→version 2: elided the code to support more than 3 doors and their outputs.
(→version 2: elided the code to support more than 3 doors and their outputs.) |
|||
Line 3,453:
===version 2===
▲parse arg # d seed . /*obtain the optional args from the CL.*/
if #=='' | #=="," then #= 1000000 /*Not specified? Then 1 million trials*/
if datatype(seed, 'W') then call random ,, seed /*Specified? Use as a seed for RANDOM.*/
wins.= 0 /*wins.0 ≡ stay, wins.1 ≡ switching.*/
do #; door. = 0 /*initialize all doors to a value of 0.*/
car= random(1,
?= random(1,
wins._ = wins._ + 1 /*bump count of type of win strategy.*/
end /*#*/ /* [↑] perform the loop # times. */
/* [↑] door values: 0≡goat 1≡car */
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 with
{{out|output|text= when using the default inputs:}}
<pre>
switching wins 66.
staying wins 33.
performed 1000000 times with 3 doors.
</pre>
|