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 3,330: Line 3,330:


var show;
var show;
do {
{ show = 3.rand.int }
do while {show ~~ [chosen, prize]};
show = 3.rand.int
} while (show ~~ [chosen, prize]);


given(chosen)
given(chosen) {
when (prize) { stayWins += 1 }
when (prize) { stayWins += 1 }
when (3 - show - prize) { switchWins += 1 }
when ([3 - show - prize]) { switchWins += 1 }
default { die "~ error ~" };
default { die "~ error ~" }
}
}
}


Line 3,343: Line 3,345:
{{out}}
{{out}}
<pre>
<pre>
Staying wins 34.80% of the time.
Staying wins 31.20% of the time.
Switching wins 65.20% of the time.
Switching wins 68.80% of the time.
</pre>
</pre>