Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """Probability of getting all faces of a die in N rolls"""
- import itertools
- # Number of die faces
- NUM_FACES = 6
- # Max rolls
- N_MAX = 10
- # Loop over roll counts
- for N in range(NUM_FACES, N_MAX + 1):
- # Count outcomes with all faces present
- success = sum(
- len(set(rolls)) == NUM_FACES
- for rolls in itertools.product(range(NUM_FACES), repeat=N)
- )
- # Calculate probability
- P = success / NUM_FACES**N * 100
- print(f"{success} / {NUM_FACES}^{N} = {P:.2f}%")
- # Output:
- # 720 / 6^6 = 1.54%
- # 15120 / 6^7 = 5.40%
- # 191520 / 6^8 = 11.40%
- # 1905120 / 6^9 = 18.90%
- # 16435440 / 6^10 = 27.18%
Advertisement
Add Comment
Please, Sign In to add comment