Project Euler Lab - Problem 90

#90 - Cube Digit Pairs

● AppliedOfficial difficulty: 14%CountingTier B - browser, with the efficient algorithmNot viewed
↖ Euler Lab

Each of the six faces on a cube has a different digit (\(0\) to \(9\)) written on it; the same is done to a second cube. By placing the two cubes side-by-side in different positions we can form a variety of \(2\)-digit numbers.

For example, the square number \(64\) could be formed:


In fact, by carefully choosing the digits on both cubes it is possible to display all of the square numbers below one-hundred: \(01\), \(04\), \(09\), \(16\), \(25\), \(36\), \(49\), \(64\), and \(81\).

For example, one way this can be achieved is by placing \(\{0, 5, 6, 7, 8, 9\}\) on one cube and \(\{1, 2, 3, 4, 8, 9\}\) on the other cube.

However, for this problem we shall allow the \(6\) or \(9\) to be turned upside-down so that an arrangement like \(\{0, 5, 6, 7, 8, 9\}\) and \(\{1, 2, 3, 4, 6, 7\}\) allows for all nine square numbers to be displayed; otherwise it would be impossible to obtain \(09\).

In determining a distinct arrangement we are interested in the digits on each cube, not the order.

  • \(\{1, 2, 3, 4, 5, 6\}\) is equivalent to \(\{3, 6, 4, 1, 2, 5\}\)
  • \(\{1, 2, 3, 4, 5, 6\}\) is distinct from \(\{1, 2, 3, 4, 5, 9\}\)

But because we are allowing \(6\) and \(9\) to be reversed, the two distinct sets in the last example both represent the extended set \(\{1, 2, 3, 4, 5, 6, 9\}\) for the purpose of forming \(2\)-digit numbers.

How many distinct arrangements of the two cubes allow for all of the square numbers to be displayed?

This problem is taken from Project Euler, Problem 90.
Problem text © Project Euler, licensed under CC BY-NC-SA 4.0. Original: projecteuler.net/problem=90. Published Friday, 4th March 2005, 06:00 pm. Solved by 13,367 members at time of mirroring.

Why this is useful

Mathematical Foundation. Exact counting underlies discrete pricing lattices, scenario enumeration, and combinatorial probability (Phase 7).

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 B - browser, with the efficient algorithm
Runs in the browser only with the intended efficient algorithm; a naive loop will hit the timeout.

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.