Project Euler Lab - Problem 86

#86 - Cuboid Route

● AppliedOfficial difficulty: 11%Optimal substructureTier B - browser, with the efficient algorithmNot viewed
↖ Euler Lab

A spider, S, sits in one corner of a cuboid room, measuring \(6\) by \(5\) by \(3\), and a fly, F, sits in the opposite corner. By travelling on the surfaces of the room the shortest "straight line" distance from S to F is \(10\) and the path is shown on the diagram.


However, there are up to three "shortest" path candidates for any given cuboid and the shortest route doesn't always have integer length.

It can be shown that there are exactly \(2060\) distinct cuboids, ignoring rotations, with integer dimensions, up to a maximum size of \(M\) by \(M\) by \(M\), for which the shortest route has integer length when \(M = 100\). This is the least value of \(M\) for which the number of solutions first exceeds two thousand; the number of solutions when \(M = 99\) is \(1975\).

Find the least value of \(M\) such that the number of solutions first exceeds one million.

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

Why this is useful

Algorithmic Development. Optimal substructure and state-space reasoning are exactly how American-option pricing and optimal execution are solved (Phases 13, 16).

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.