Skip to content

Instantly share code, notes, and snippets.

@iitalics
Created August 12, 2025 17:29
Show Gist options
  • Select an option

  • Save iitalics/509b1afc65fcd425cf8f791556a0d484 to your computer and use it in GitHub Desktop.

Select an option

Save iitalics/509b1afc65fcd425cf8f791556a0d484 to your computer and use it in GitHub Desktop.
# expected rate to get n drops
def true_exp(n):
if n <= 0:
return 0
p2 = 1/100 # 2 drops
p1 = 18/100 # 1 drop
p0 = 81/100 # 0 drops
# E(n) = 1 + p2 E(n-2) + p1 E(n-1) + p0 E(n)
# (1 - p0) E(n) = 1 + p2 E(n-2) + p1 E(n-1)
# E(n) = (1 + p2 E(n-2) + p1 E(n-1)) / (1 - p0)
e2 = true_exp(n - 2)
e1 = true_exp(n - 1)
return (1 + p2 * e2 + p1 * e1) / (1 - p0)
print(true_exp(10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment