Created
January 24, 2016 00:07
-
-
Save Goodwine/196bca2b4bf72e630dfb to your computer and use it in GitHub Desktop.
How many times do I need to try something that has an `odds` probability of winning to ensure with a certain level of `confidence` that I'll win.
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 rolls(odds, confidence) { | |
var prob = 0; | |
for (var n = 0; prob < confidence;) { | |
n++; | |
prob += calcProb(1, odds) * calcProb(n-1, 1-odds); | |
} | |
return n; | |
} | |
function calcProb(times, odds) { | |
return Math.pow(odds, times); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment