Created
May 23, 2017 12:21
-
-
Save serega6531/0eb3b8c611c1a85eca0e3abede8730b1 to your computer and use it in GitHub Desktop.
Программа для проверки парадокса Монти Холла (https://ru.wikipedia.org/wiki/Парадокс_Монти_Холла)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rnd(a, b) { | |
return Math.floor(Math.random() * (b - a)) + a; | |
} | |
function randBool() { | |
return Math.random() >= .5; | |
} | |
var success = 0; | |
var tries = 1000000; | |
for (var i = 0; i < tries; i++) { | |
var won = rnd(1, 4); | |
var chosen = rnd(1, 4); | |
var opened = 0; | |
if (chosen == won) switch (chosen) { | |
case 1: | |
opened = randBool() ? 2 : 3; | |
break; | |
case 2: | |
opened = randBool() ? 1 : 3; | |
break; | |
case 3: | |
opened = randBool() ? 1 : 2; | |
} else | |
opened = 6 - (chosen + won); | |
if (chosen != won) success++; | |
} | |
console.log((success / tries * 100) + '%'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment