🔢 Recamán's Sequence
About this simulation
Recamán's Sequence is an integer sequence, catalogued as OEIS A005132, popularised by the Colombian mathematician Bernardo Recamán Santos. Starting from zero, each new term either steps backward or forward along the number line, and the rule for choosing which direction to go — combined with a strict “no repeats” condition — produces a surprisingly intricate, self-avoiding path that has become one of the most recognisable curiosities in recreational mathematics.
How it works
- The sequence starts at a(0) = 0.
- For each step n, the simulation first tries subtracting n from the previous term.
- If that result is positive and has not appeared earlier in the sequence, it is accepted.
- Otherwise the simulation adds n to the previous term instead, which always produces a brand-new value.
- Each transition is drawn as a semicircular arc: above the number line for a subtraction step, below it for an addition step.
Key equations
a(0) = 0
a(n) = a(n-1) - n if that value is positive and unused, otherwise a(n) = a(n-1) + n.
Controls
- Number of terms — how many terms of the sequence to compute and draw.
- Animation speed — how many arcs are drawn per second as the pattern builds.
- Pause / Resume — freeze or continue the drawing animation.
- Reset — return every control and the view to its default state.
- Scroll / drag — zoom and pan the canvas to inspect any part of the pattern up close.
Did you know?
It is conjectured — but still not proven — that every non-negative integer eventually appears somewhere in Recamán's Sequence. The visualisation is also famous well beyond mathematics: converting each arc into a musical note produces the strangely hypnotic “Recamán's Sequence” audio-visualisations that have racked up millions of views online.