Skip to content

Instantly share code, notes, and snippets.

@cmelchior
Created August 21, 2025 10:38
Show Gist options
  • Save cmelchior/5416c26b4745536d2b2db17faf42dacc to your computer and use it in GitHub Desktop.
Save cmelchior/5416c26b4745536d2b2db17faf42dacc to your computer and use it in GitHub Desktop.
// ps: Probability array of "success" for each roll
fun luckSymExact(ps: List<Double>, successes: Int): Double {
// Check for all fail/succeed case, since this will reported wrong otherwise
val variance = ps.sumOf { it * (1 - it) }
if (variance == 0.0) {
return when (successes > 0) {
true -> 100.0
false -> -100.0
}
}
val pmf = pbPmf(ps)
val mid = midCdf(pmf, successes) // in [0,1]
return (2.0 * mid - 1.0) * 100.0 // in [-100,+100]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment