Project Euler Lab - Problem 376

#376 - Nontransitive Sets of Dice

● ResearchOfficial difficulty: 77%Two-player gamesTier C - reduced scale in browser; full scale in notebookNot viewed
↖ Euler Lab

Consider the following set of dice with nonstandard pips:

Die \(A\): \(1\) \(4\) \(4\) \(4\) \(4\) \(4\)
Die \(B\): \(2\) \(2\) \(2\) \(5\) \(5\) \(5\)
Die \(C\): \(3\) \(3\) \(3\) \(3\) \(3\) \(6\)

A game is played by two players picking a die in turn and rolling it. The player who rolls the highest value wins.

If the first player picks die \(A\) and the second player picks die \(B\) we get
\(P(\text{second player wins}) = 7/12 \gt 1/2\).

If the first player picks die \(B\) and the second player picks die \(C\) we get
\(P(\text{second player wins}) = 7/12 \gt 1/2\).

If the first player picks die \(C\) and the second player picks die \(A\) we get
\(P(\text{second player wins}) = 25/36 \gt 1/2\).

So whatever die the first player picks, the second player can pick another die and have a larger than \(50\%\) chance of winning.
A set of dice having this property is called a nontransitive set of dice.

We wish to investigate how many sets of nontransitive dice exist. We will assume the following conditions:

  • There are three six-sided dice with each side having between \(1\) and \(N\) pips, inclusive.
  • Dice with the same set of pips are equal, regardless of which side on the die the pips are located.
  • The same pip value may appear on multiple dice; if both players roll the same value neither player wins.
  • The sets of dice \(\{A,B,C\}\), \(\{B,C,A\}\) and \(\{C,A,B\}\) are the same set.

For \(N = 7\) we find there are \(9780\) such sets.
How many are there for \(N = 30\)?

This problem is taken from Project Euler, Problem 376.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=376. Published Sunday, 18th March 2012, 01:00 am. Solved by 338 members at time of mirroring.

Why this is useful

Probability Statistics. Expectation and state-based probability reasoning underpin pricing, risk, and statistical inference (Phases 7, 11, 13).

We classify relevance honestly - not every Euler problem is a trading application.

Learning mode

Pick how much scaffolding you want. Your choice is remembered per problem.

Scratchpad

Mathematical notes, formulas, pseudocode, hypotheses, complexity notes. Saved automatically with your progress.

Python workbench

Tier C - reduced scale in browser; full scale in notebook
Browser runs a reduced, clearly-labelled educational scale; the original scale is provided in a local notebook.

Real Python (Pyodide) in a sandboxed Web Worker - no network, no filesystem, no DOM access. Ctrl/Cmd+Enter runs. Escape leaves the editor. Stop terminates the worker.

Python runtime not loaded (it boots on first run - a one-time local load).

Check your answer

Answers are checked against a salted hash held in a separate file - not printed in this page. This prevents accidental spoilers; it is not cryptographic protection (see the build notes).

Progressive hints

Confidence

Low confidence schedules this problem for spaced review, even if you solved it.

Reference solution

Spoiler
The complete original explanation (interpretation, naive approach, insight, proof, complexity, Python implementation, tests, common mistakes, alternatives) is hidden and lazy-loaded. Reveal it only after a meaningful attempt - the struggle is where the learning happens.