🔢 Recamán's Sequence
Watch Recamán's Sequence build itself one term at a time as semicircular arcs above and below a number line. Explore the recurrence a(n) = a(n-1) − n or a(n-1) + n, zoom, pan, and count avoided collisions live.
About this simulation
This tool visualises Recamán's Sequence (OEIS A005132), a deceptively simple integer sequence that produces a strikingly intricate picture. Starting from zero, each step either subtracts or adds the step number to the previous term, chosen by a strict rule that forbids repeated values. Plotting each transition as a semicircular arc above or below a number line reveals the sequence's famous looping “eye” pattern as it grows term by term.
🔬 What it shows
Beginning at a(0)=0, term a(n) is a(n-1)−n whenever that value is positive and has not already appeared, otherwise it is a(n-1)+n. Each new term is joined to the previous one by a semicircular arc drawn above the line for a subtraction and below it for an addition, so the whole animation traces out Recamán's Sequence one arc at a time.
🎮 How to use
Set how many terms to compute with the terms slider and how fast the arcs are drawn with the speed slider. Pause or resume the animation at any point, and use Reset to start over. Scroll or pinch on the canvas to zoom, and click-drag to pan around and inspect any part of the growing pattern.
💡 Did you know?
Every time the subtraction step would land on a non-positive or already-used number, the simulation is forced to add instead — the stats panel counts these forced “collisions avoided” live as the sequence unfolds.
Frequently asked questions
What is Recamán's Sequence?
Recamán's Sequence is an integer sequence defined by a(0)=0, and for n≥1, a(n)=a(n-1)−n if that value is positive and has not occurred earlier in the sequence, otherwise a(n)=a(n-1)+n. It is named after Colombian mathematician Bernardo Recamán Santos and catalogued as OEIS sequence A005132.
Why do the arcs alternate above and below the line?
The direction of each arc encodes which branch of the rule was taken. An arc drawn above the number line means the term was reached by subtracting the step number from the previous term; an arc below the line means the step number was added instead because subtracting would have produced a non-positive or already-used value.
What does “collisions avoided” mean?
Every time the subtraction branch a(n-1)−n cannot be used — because it is zero or negative, or because that value already appears earlier in the sequence — the simulation falls back to addition instead. The stats panel counts how many times this forced switch has happened so far.
Is it known whether every integer appears in the sequence?
No. It is conjectured that every non-negative integer eventually appears somewhere in Recamán's Sequence, and this has been verified for enormous numbers of terms computationally, but no one has proven it holds for every integer without exception. It remains an open problem in recreational mathematics.
Why does the visualization look like an eye?
Because early terms tend to reuse a fairly narrow range of values, the arcs generated in the first few hundred steps loop back on themselves repeatedly, layering large and small semicircles on both sides of the line. Viewed together, these nested loops resemble the layered curves of an eye — a pattern that has made the sequence popular for musical and generative-art renditions online.
Watch Recamán's Sequence build itself one term at a time as semicircular arcs above and below a number line, following the recurrence a(n) = a(n-1) - n or a(n-1) + n.
2D · HTML5 Canvas 2D · 60 FPS target · runs fully client-side, no install