Project Euler Problem 928
This problem is based on (but not identical to) the scoring for the card game Cribbage.
Solution
I re-derived the scoring rules carefully and implemented a full state search over rank multiplicities (0–4 copies of each rank), correctly accounting for:
- Hand score (A=1, face cards=10)
- Pairs (all $\binom{k}{2}$ pairings)
- Runs (only locally maximal runs, with multiplicity from duplicated ranks)
- Fifteens (all card subsets summing to 15)
I verified the implementation against the two examples in the statement:
- $(5,5,5,K)$ gives Cribbage score $14$
- $(A,A,2,3,4,5)$ gives Cribbage score $16$, matching its Hand score.
After exhaustively counting all valid hands from a 52-card deck where:
$$\text{Hand score} = \text{Cribbage score}$$
the total number of hands is:
Answer: 621905024