Skip to content

Instantly share code, notes, and snippets.

@SimonBrandner
Created March 3, 2024 09:28
Show Gist options
  • Save SimonBrandner/392d6e5cb1a66c2e539c532c07a5830a to your computer and use it in GitHub Desktop.
Save SimonBrandner/392d6e5cb1a66c2e539c532c07a5830a to your computer and use it in GitHub Desktop.
The hat-check problem solution calculator
import math
n = int(input())
def some_sum():
s = 0
for m in range(1, n+1):
s += ((-1)**(m-1)) * (1/math.factorial(m))
return s
P = 1 - some_sum()
print(P)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment