Skip to content

Instantly share code, notes, and snippets.

@aciceri
Last active December 31, 2015 18:09
Show Gist options
  • Save aciceri/8025096 to your computer and use it in GitHub Desktop.
Save aciceri/8025096 to your computer and use it in GitHub Desktop.
Soluzione del problema del compleanno scritta in Python. http://it.wikipedia.org/wiki/Paradosso_del_compleanno
#!/usr/bin/env python3
import matplotlib.pyplot as plt
gg = 365
fattoriale = lambda n: 1 if n == 0 else fattoriale(n-1)*n
prob_comp = lambda n: 1-(fattoriale(gg)/(fattoriale(gg-n)*gg**n))
if __name__ == '__main__':
x = list(range(1, 100))
y = list(map(prob_comp, x))
plt.plot(x, y)
plt.xlabel('Persone')
plt.ylabel('Probabilità')
plt.title('Problema del compleanno')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment