Skip to content

Instantly share code, notes, and snippets.

@lvaughn
Created January 14, 2024 18:27
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 lvaughn/42766c2ae8b8875148cfad0a5f8e0ad5 to your computer and use it in GitHub Desktop.
Save lvaughn/42766c2ae8b8875148cfad0a5f8e0ad5 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Answer to the Fiddler On the Proof newsletter for Jan 12, 2024
from fractions import Fraction
from itertools import combinations
dice_values = [4, 6, 8, 10, 12, 20]
# Part 1
probs = []
for pair in combinations(dice_values, 2):
# The probability of both getting the same value is 1/<larger of the two dice>
probs.append(Fraction(1, max(pair)))
result = sum(probs)/len(probs)
print("Part 1", result, float(result))
# Part 2
probs = []
for triple in combinations(dice_values, 3):
# The probability is the 1/<product of the two largest dice sizes>
in_order = list(sorted(triple))
probs.append(Fraction(1, in_order[1]*in_order[2]))
result = sum(probs)/len(probs)
print("Part 2", result, float(result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment