Skip to content

Instantly share code, notes, and snippets.

@ricbit

ricbit/recurrence.py

Created Apr 17, 2021
Embed
What would you like to do?
Expected number of packs to complete an album (linear)
import math
evalue = [0] * 181
norm = math.comb(180, 4)
for i in range(1, 181):
ans = math.comb(i, 0) * math.comb(180 - i, 4 - 0) / norm
for k in range(1, 5):
if i - k >= 0:
px = math.comb(i, k) * math.comb(180 - i, 4 - k) / norm
ans += px * (1 + evalue[i - k])
ans /= 1 - math.comb(180 - i, 4) / norm
evalue[i] = ans
print(i, evalue[i])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment