Skip to content

Instantly share code, notes, and snippets.

@dsetzer
Created October 25, 2021 13:17
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 dsetzer/92796ac864acd55b61e3b9dd0cf3959b to your computer and use it in GitHub Desktop.
Save dsetzer/92796ac864acd55b61e3b9dd0cf3959b to your computer and use it in GitHub Desktop.
Finds the cumulative win probability of a target payout in bustabit/bustadice. Results parameter expects an ordered array of numbers representing the games bust history.
/**
* Calculates current cumulative geometric probability
* @param payout Target payout to calculate for
* @param results Array of ordered results
* @param precision Num decimal places accuracy
* @param debug Output result slice to console
* @returns Cumulative geometric win probability
*/
function getCumulativeProb(payout, results, precision, debug = false) {
let prc = 10 ** Math.max(1, Math.min((precision || 18), 18), 1);
if (Array.isArray(results) && results.length) {
for (let i = 0, j = results.length; i < j; i++) {
if (results[j - i] >= payout) {
let pmf = (1 - ((1 - (0.99 / payout)) ** i));
let res = Math.min(1, Math.max(Math.round(pmf * prc) / prc, 0));
(debug && console.debug(`${payout}x : ${res*100}% [${results.slice(-i)}](${i})`));
return res;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment