Skip to content

Instantly share code, notes, and snippets.

@moritz
Created September 23, 2011 19:02
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 moritz/1238173 to your computer and use it in GitHub Desktop.
Save moritz/1238173 to your computer and use it in GitHub Desktop.
Analytical solution (atempt)
N = number of coin flips until one bucket is empty
P(N) = propability that the exactly N coin flips happened.
Expected number of remaining things in one bucket:
remain = 80 - [+] (40..79).map({ $_ * P($_) });
so, what's P(N)?
P(N = 40) = 2 * 0.5**40
P(N = 41) = 2 * 0.5**41 * 39 * 39 / 2
P(N) = 2 * 0.5**N * 39**(40-N) / (40-N)!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment