Guest User

prob_all_faces.py

a guest
Aug 6th, 2026
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.63 KB | Source Code | 0 0
  1. """Probability of getting all faces of a die in N rolls"""
  2.  
  3. import itertools
  4.  
  5. # Number of die faces
  6. NUM_FACES = 6
  7.  
  8. # Max rolls
  9. N_MAX = 10
  10.  
  11. # Loop over roll counts
  12. for N in range(NUM_FACES, N_MAX + 1):
  13.     # Count outcomes with all faces present
  14.     success = sum(
  15.         len(set(rolls)) == NUM_FACES
  16.         for rolls in itertools.product(range(NUM_FACES), repeat=N)
  17.     )
  18.  
  19.     # Calculate probability
  20.     P = success / NUM_FACES**N * 100
  21.     print(f"{success} / {NUM_FACES}^{N} = {P:.2f}%")
  22.  
  23. # Output:
  24. # 720 / 6^6 = 1.54%
  25. # 15120 / 6^7 = 5.40%
  26. # 191520 / 6^8 = 11.40%
  27. # 1905120 / 6^9 = 18.90%
  28. # 16435440 / 6^10 = 27.18%
  29.  
Advertisement
Add Comment
Please, Sign In to add comment