Square-Sum Cycle
& Open-Path Generator
Arrange every integer of an interval so that each pair of neighbours adds up to a perfect square. The generator first looks for a closed cycle; if no cycle exists, it looks for a complete open path. It says “impossible” only when this is proved.
An interval often has many different closed cycles — different ways to arrange the same numbers on a circle. For example, 1–32 and 1–33 have exactly one each, 1–34 has 11, 1–35 has 57 and 1–40 has 64. A cycle turned round or read backwards is the same cycle, so it is counted once. Use Alternative solutions to list every cycle of an interval, draw any of them, and download the complete list.
Every start, with the reason
How to read the result
The generator has three parts: 1 a closed cycle or an open path for an interval, 2 the alternative solutions — every different closed cycle of that interval, listed and counted — and 3 which starts give a closed cycle for a fixed end.
Closed cycle — every neighbouring pair, including the last and the first number, adds up to a perfect square.
Open path — every neighbouring pair adds up to a square, but the two ends do not. The circle is left open between the ends.
Proved impossible — either a simple counting argument (a number with no square-sum partner, a number with only one partner inside a cycle, more than two such numbers in a path, or a graph in separate pieces) or a complete search of every arrangement. Not found in time only means the search stopped: try a longer search time.
Alternative solutions (part 2) lists every different closed cycle of the interval (a cycle turned round or read backwards counts once). Click a row to draw it; download the whole list as TXT or CSV for Excel. If the time limit ends first, the list says “at least”, so raise the time limit for the complete answer.
Which starts close? fixes the end b and tests every start a = 1, 2, …, b − 2. Most starts are ruled out at once by the counting argument (some number has fewer than two square-sum partners — for example, for ends 41 to 48 the number 32 keeps only the partner 17 once 4 is left out). The few that remain are settled by a search that stops at the first closed cycle, or proves there is none. Tick count the cycles too to also count every closed cycle of each valid start. Click a valid start to draw a cycle.
Cycle order places the numbers around the circle in the order of the cycle, with each square sum in a coloured box between neighbours. Natural order places 1, 2, 3, … around the circle and draws each square-sum link as a coloured chord.