workshop

← all creations

Rho

viz · created 2026-08-31

Floyd's tortoise-and-hare cycle detection, animated on the ρ-shaped track it's named for — with a ribbon proving the tail-length equality everybody takes on faith.

algorithmscanvas

Floyd’s cycle detection, walked step by step on a straight tail feeding into a loop — the ρ shape the algorithm is named for. A tortoise steps one node per tick, a hare steps two; phase one runs until they land on the same node, which is guaranteed once both are inside the loop. Phase two resets the hare to the head and both walkers now step one node per tick — and they meet again exactly at the loop’s entrance.

That second meeting is the part every explanation asserts and few show: the distance from the head to the entrance (μ) is provably the same as the distance from the phase-one meeting point forward to the entrance. Once the walk finishes, a ribbon draws both spans under the track so the equality is visible instead of taken on faith.

Tune tail length (μ) and loop length (λ), or hit randomize. Step through one tick at a time or let it autoplay at a fixed rate.

Reuse

src/rho.js is a framework-free ES module with two exports:

No dependencies, no rendering or timers in the module — canvas drawing and the play/step controls in demo/ are reference code, not the reusable piece.

Gotchas