What Euler left us: the topology behind one-stroke puzzles
While building Loop Trail, I reread Euler's 7-page paper from 1736. It solved a strolling citizens' puzzle, and on the way invented an entire branch of mathematics. This article tells that story and explains how I use Euler's conclusion to generate puzzle levels.
Königsberg, 1736
The city of Königsberg (now Kaliningrad, Russia) had a river with two islands. The four city districts (including the islands) were connected by 7 bridges. Citizens posed a puzzle: can you start somewhere, walk every bridge exactly once, and end up back where you started (or anywhere)?
Euler was 29 and working at the St. Petersburg Academy when he got the problem. After a few days he proved: no. He then wrote a paper, *Solutio problematis ad geometriam situs pertinentis* (Solution to a problem on the geometry of position), sent to the Berlin Academy.
The paper's real contribution wasn't the answer; it was the method. Euler first noticed: this problem doesn't depend on bridge length, on island shape, on distances. It depends only on which place connects to which. That's the birth of topology — a geometry that ignores size and distance, focusing on connection only.
Odd vertices
Euler's proof is so simple it sounds trivial, but it's airtight. He observed:
For any vertex that isn't the start or end of the walk, you must enter and exit the same number of times. So the number of bridges (degree) at that vertex must be even.
Modernized: treat each place as a node, each bridge as an edge between two nodes. If a vertex is traversed fully in one stroke (enter = exit), its degree (number of edges) must be even.
Only two exceptions: the start and the end. If you don't need to return to start, the start and end can have odd degree (you exit once or enter once). If you must return, the start and end must also be even.
So the conclusions:
- One-stroke return possible (Eulerian circuit): every vertex must be even — odd-vertex count = 0
- One-stroke without return (Eulerian path): exactly 2 odd vertices, start and end must be those two
- Impossible: any other count (4, 6, 8...)
Königsberg's four districts, after the 7 bridges, had degrees 3, 5, 3, 3 — all odd, 4 odd vertices. Impossible.
Why this discovery mattered
In Euler's time, mathematics was about length, angle, area. He was the first to say: there's a geometry that doesn't care about those. It evolved into graph theory and topology, used today in Google Maps routing, internet protocol design, chip layout, social network analysis — anywhere you need a "network."
When I implemented BFS for Pixel Path's shortest-path display, I was using graph theory — treating maze cells as nodes, connecting neighbors with edges, running breadth-first search. Euler's paper laid the theoretical foundation.
How I use this to generate levels
All 10 levels of Loop Trail are hand-designed (no algorithm), but every one obeys Euler's theorem: odd-vertex count must be 0 or 2. It's the only reliable test for solvability.
My design flow:
- Sketch nodes (4-8, evenly spread)
- Connect with edges, computing current degree after each addition
- Check odd vertices: if the count is 0 or 2, the level is solvable
- If 4 or more odd vertices, add or remove an edge until it fits
Difficulty progression depends on which: odd-vertex count = 0 (Eulerian circuit) is actually easier because you can start from any vertex. Odd-vertex count = 2 (Eulerian path) is harder because you must identify the two odd vertices and start from one. I set levels 1-4 with count = 0 (tutorial), middle 4 mixed, last 2 with count = 2 and complex graphs.
Implementation gotchas
Two details bit me during coding.
First: edge bidirectionality. In my game players can walk from A to B or B to A. Each edge is undirected. JavaScript has no native graph structure, so I built it myself. I store edges as `{a: 0, b: 1}` and lookup via `findEdge(a, b)` which checks both `(e.a===a && e.b===b)` and the swap.
Second: touch hit-testing nodes. I initially used `nodeAt(x, y)` to check if the touch point fell inside a node's circle. But finger touches on mobile drift by 5-10 pixels, so players often missed nodes while dragging. I expanded the hit radius to 1.6x the visual node radius. Instant UX improvement.
Who Euler was
A digression. Euler is history's most prolific mathematician, with over 800 published papers. He went blind after age 60 but kept dictating papers — performing all computations in his head, then dictating to a secretary. The day he died, he was reportedly discussing Uranus' orbit with his grandson at play.
Not your typical brain.
Closing
One-stroke games look like simple toys, but their roots reach back to 1736. Every player completing a Loop Trail level is unknowingly applying Euler's theorem.
That historical thickness, to me, is one of the biggest differences between hand-built games and assembly-line games. When I know my code stands on 290 years of mathematics, I write more carefully.
If you're stuck on a Loop Trail level: count edges per node, find odd vertices. If 2, start from one of them; if 0, any vertex works, but mind path connectivity. Theory guarantees solvability.
Leo is BverGame's co-engineer. Euler's 1736 paper and the history of graph theory are accessible via Wikipedia's "Seven Bridges of Königsberg." This piece is a popular re-telling, not a rigorous mathematical proof.