Cuboid Route

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 a famous one from Project Euler. This does not have a simple arithmetic solution and calls for the knowledge of Pythagorean triples.

The important fact that we should note is: If (a, b, c) is a Pythagorean triple (groups of three positive integers a, b, and c that fit the rule $a^2 + b^2 = c^2$) and a > b > c, the shortest path across the cuboid with sides (a, b, c) is simply a. This is because the longest diagonal of the cuboid is a, and you can get from one corner to the opposite by “unfolding” the cuboid and forming a straight line of length a along the surface.

So the cuboids we’re looking for must have sides of a, b, and k, where:
1. (a, b, c) are Pythagorean triples
2. a <= b <= c 3. k must be an integer such that a <= k <= b. All we have to do is to generate all Pythagorean triples until the number of cuboids exceeds one million. To do this we can use the parametrization of Pythagorean triples. If (a, b, c) is a Pythagorean triple, then there exist integers m and n such that: a = m^2 - n^2 b = 2mn c = m^2 + n^2 m > n > 0

We can use this formula to generate all Pythagorean triples! It is also important to note that not all Pythagorean triples arise uniquely from (m, n): some arise their multiples. For example, (3, 4, 5) and (6, 8, 10) result from m = 2, n = 1.

So to count all cuboids, we need to iterate over all Pythagorean triples, count the number of b’s that could be sides of the cube, and multiply the count by the number of multiples of (a, b, c) that fit in the given bound M.

This is not a question that is meant to be solved analytically. This is meant to be solved computationally in a programming language like Python, Java, or anything that can handle these sorts of computations. Doing this by hand would take an enormous amount of time and is not practical.

You could use the following algorithm and carry out the steps until the number of cuboids exceeds one million:

1. Initialize number_of_cuboids to 0 and M to 0

2. While number_of_cuboids <= 1,000,000 For each integer m from 2 to M: For each integer n from 1 to m-1: Compute a, b, c If a and b are both <= M, increment number_of_cuboids If a <= M and b <= 2M, increment number_of_cuboids by floor(b/2) - m + 1 3. Print the value of M when the while loop ends. The actual value of M will be found through running the above algorithm on computer. You can certainly write a quick script in a language such as Python to find it.

More Answers:
Path Sum: Four Ways
Monopoly Odds
Counting Rectangles

Error 403 The request cannot be completed because you have exceeded your quota. : quotaExceeded

Share:

Recent Posts