Recamán’s Sequence
Visualisation

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.

Number of Terms

500

Animation Speed

1.0x

View

1.0x

Sequence Values

Statistics

Current term (n)0
Current value a(n)0
Unique values1
Collisions avoided0
Blocked by negative0
Smallest value not yet seen1

Recurrence Relation

a(n) ={
a(n − 1) − nif a(n − 1) − n > 0 and ∉ S
a(n − 1) + notherwise
  • Start with a(0) = 0
  • For n ≥ 1, try a(n − 1) − n
  • If the result is negative or already in the sequence, use a(n − 1) + n instead
  • S is the set of all previous terms

Mini Map (full sequence)

The science

Definition (OEIS A005132). a(0)=0; for n≥1 take a(n)=a(n−1)−n when that number is positive and has not appeared yet, otherwise a(n)=a(n−1)+n. Only the backward jump is checked, so a forward jump can land on an old value and “Unique values” (distinct terms so far) can be smaller than n+1 – e.g. 42 appears at n=20 and n=24. “Collisions avoided” counts the steps where the backward jump would have landed on an already visited number, and “Blocked by negative” the steps where it would have left the non-negative integers.

Drawing. Each step n is a semicircle on the segment between a(n−1) and a(n); arcs alternate above (even n) and below (odd n) the line. Vertical radii are squashed (above 0.85, below 0.5) for a compact picture – the horizontal extent is exact.

What is known. Since a(n) ≤ n(n+1)/2 the sequence grows at most quadratically (each step adds at most n); in practice it alternates between slow backward walks and large forward jumps. The Recamán conjecture – every non-negative integer eventually appears – is unproven (checked by computer to very large n). Watch the “Smallest value not yet seen” counter: it moves up in sudden jumps when a stubborn gap is finally filled.

Honest simplifications. The animation shows a finite prefix (up to 900 terms). The sweeping arc timing is cosmetic. The mini map draws all terms at once, upper arcs only.

Self-check (independent computation): running…

Space play/pause · R reset · + / − zoom · ← → pan · wheel zooms · drag pans