Created
December 2, 2022 10:28
-
-
Save mormegil-cz/9d3ee4704c005f939a1d151c9d23d988 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let successes = 0; | |
let failures = 0; | |
for (let iter = 0; iter < 100000000; ++iter) { | |
let counts = [3,0,0,0]; | |
while (counts.length > 1) { | |
let loser = Math.round(Math.random() * counts.length); | |
if (loser === 0) { | |
break; | |
} | |
if (++counts[loser] >= 4) { | |
counts.splice(loser, 1); | |
} | |
} | |
if (counts.length > 1) ++failures; | |
else ++successes; | |
} | |
console.log(`${successes} (${failures}) -> ${(100.0 * successes / (successes+failures)).toFixed(2)} %`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment