Monty Hall problem: Difference between revisions

Content added Content deleted
imported>Myrmidon
(→‎{{header|Chapel}}: put the old version back too)
imported>Grootson
Line 3,031: Line 3,031:


=={{header|MATLAB}}==
=={{header|MATLAB}}==
<syntaxhighlight lang="matlab">function montyHall(numDoors,numSimulations)
<syntaxhighlight lang="matlab">
wins = ceil(3*rand(1e8,1)) - ceil(3*rand(1e8,1))
mprintf('chance to win for staying: %1.6f %%\nchance to win for changing: %1.6f %%', 100*length(wins(wins==0))/length(wins), 100*length(wins(wins<>0))/length(wins))
end</syntaxhighlight>

<syntaxhighlight lang="matlab">

function montyHall(numDoors,numSimulations)


assert(numDoors > 2);
assert(numDoors > 2);