Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
32
Task/Monty-Hall-problem/ActionScript/monty-hall-problem.as
Normal file
32
Task/Monty-Hall-problem/ActionScript/monty-hall-problem.as
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package {
|
||||
import flash.display.Sprite;
|
||||
|
||||
public class MontyHall extends Sprite
|
||||
{
|
||||
public function MontyHall()
|
||||
{
|
||||
var iterations:int = 30000;
|
||||
var switchWins:int = 0;
|
||||
var stayWins:int = 0;
|
||||
|
||||
for (var i:int = 0; i < iterations; i++)
|
||||
{
|
||||
var doors:Array = [0, 0, 0];
|
||||
doors[Math.floor(Math.random() * 3)] = 1;
|
||||
var choice:int = Math.floor(Math.random() * 3);
|
||||
var shown:int;
|
||||
|
||||
do
|
||||
{
|
||||
shown = Math.floor(Math.random() * 3);
|
||||
} while (doors[shown] == 1 || shown == choice);
|
||||
|
||||
stayWins += doors[choice];
|
||||
switchWins += doors[3 - choice - shown];
|
||||
}
|
||||
|
||||
trace("Switching wins " + switchWins + " times. (" + (switchWins / iterations) * 100 + "%)");
|
||||
trace("Staying wins " + stayWins + " times. (" + (stayWins / iterations) * 100 + "%)");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue