Skip to content

Instantly share code, notes, and snippets.

@Goodwine
Created January 24, 2016 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Goodwine/196bca2b4bf72e630dfb to your computer and use it in GitHub Desktop.
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.
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