Skip to content

Instantly share code, notes, and snippets.

@michaelochurch
Created November 22, 2020 17:19
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 michaelochurch/84ac5e8d04af56a64e9972678db496c6 to your computer and use it in GitHub Desktop.
Save michaelochurch/84ac5e8d04af56a64e9972678db496c6 to your computer and use it in GitHub Desktop.
>>> def dp():
... r = random.randint(1, 8)
... if r < 4: return 0
... if r < 7: return 1
... if r == 7: return 2
... if r == 8:
... out = 3
... while random.randint(1, 8) == 8:
... out += 1
... return out
>>> def ndP(n):
... return sum(dp() for x in range(n))
>>> def med_ndP(m, n):
... res = [ndP(n) for x in range(m)]
... res.sort()
... return res[m // 2]
>>> results = [med_ndP(3, 4) - (4 + med_ndP(3, 4)) for x in range(100000)]
>>> len([x for x in results if x > 0])
1331
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment