Monty Hall problem: Difference between revisions

no edit summary
m (Prob cat)
No edit summary
Line 7:
 
Simulate at least a thousand games using three doors for each strategy <u>and show the results</u> in such a way as to make it easy to compare the effects of each strategy.
 
=={{header|ActionScript}}==
<actionscript>
package {
import flash.display.Sprite;
 
public class MonteyHall extends Sprite
{
public function MonteyHall()
{
var iterations:int = 30000;
var doors:Array = [0, 0, 0];
var switchWins:int = 0;
var stayWins:int = 0;
for (var i:int = 0; i < iterations; i++)
{
doors[Math.round(Math.random() * 2)] = 1;
var choice:int = Math.round(Math.random() * 2);
var shown:int;
do
{
shown = Math.round(Math.random() * 2);
} while (doors[shown] != 1 && shown != choice);
stayWins += doors[choice];
switchWins += (doors[choice] == 0)? 1: 0;
doors = [0, 0, 0];
}
trace("Switching wins " + switchWins + " times. (" + (switchWins / iterations) * 100 + "%)");
trace("Staying wins " + stayWins + " times. (" + (stayWins / iterations) * 100 + "%)");
}
}
}
</actionscript>
Output:
<pre>
Switching wins 18788 times. (62.626666666666665%)
Staying wins 11212 times. (37.37333333333333%)
</pre>
 
=={{header|Ada}}==
Anonymous user