Created
April 23, 2022 14:20
-
-
Save anonymoustafa/3676b3f88f37d15ebb699637abdf2234 to your computer and use it in GitHub Desktop.
iam_vee challenge
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
// link to the main tweet: https://twitter.com/iam_vee/status/1517357609170386944?s=20&t=MN3UgYbDae5NCTSoeh5mzg | |
var sum = 0, counter = 0, | |
maxTries = 1000_000; | |
for (let i = 1; i <= maxTries; i++) { | |
counter++; | |
while (1) { | |
sum++; | |
if (gimmeRand1to6() == 6) break; | |
} | |
} | |
let probabilty = sum / maxTries; | |
console.log(`the probabilty of happening 6 is almost equal to ${probabilty} after ${counter} trials.`); | |
function gimmeRand1to6() { | |
return (Math.floor(Math.random() * 6)+1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment