Recaman Sequence Calculator

Find a term of Recamán's sequence, which subtracts the index when possible and adds it otherwise.

Math and PercentUpdated 2026-11-182 min read
Recaman Sequence Calculator
A whole number from 0 to 500.
Recaman term
...
Previous term...
Change from previous...

What it does

Recamán's sequence is generated by a simple rule with a surprising result. Begin at zero. For step n, try to subtract n from the previous term. If the result is positive and has not appeared earlier, use it. Otherwise add n instead.

The first terms are 0, 1, 3, 6, 2, 7, 13, 20 and 12. The sequence wanders up and down rather than growing steadily, and its visual plot is a familiar example of unexpected structure from a trivial rule.

The rule requires tracking every value already used, because a subtraction is rejected if it would revisit an earlier term. This page keeps that set explicitly, so the term at each index is computed exactly.

The output shows the term, the term before it and the change between them. A negative change means a successful subtraction, while a positive change means the rule fell back to addition.

The index limit is 500, which keeps the used set small and the answer immediate. The search never needs a guard because each step has a deterministic outcome.

How to use

  1. Enter an index n from 0 to 500.
  2. Read the Recamán term in the main result box.
  3. Check the previous term beside it.
  4. A negative change means a subtraction was used.
  5. The default index 8 reproduces the worked example.
  6. Try index 4 to see the sequence drop from 6 to 2.

Formula

a(0) = 0; for n > 0, a(n) = a(n - 1) - n if that value is positive and unused, otherwise a(n - 1) + n
n
The current step index.
a(n - 1)
The previous term.
used set
All values produced earlier in the sequence.

The subtraction is attempted first. It is accepted only when the result is greater than zero and not already in the used set; otherwise the addition is taken. Because each new value is recorded, the sequence never repeats a term by construction.

Worked example

Example: index 8

The page opens with index 8.

  1. Start with a(0) = 0.
  2. At step 1, 0 - 1 is negative, so add: a(1) = 1.
  3. At step 2, 1 - 2 is negative, so add: a(2) = 3.
  4. At step 3, 3 - 3 is zero, so add: a(3) = 6.
  5. At step 4, 6 - 4 = 2 is new, so a(4) = 2.
  6. Continuing gives a(5) = 7, a(6) = 13 and a(7) = 20.
  7. At step 8, 20 - 8 = 12 is new, so a(8) = 12.
  8. The tool reports 12, previous term 20, and change -8.

Reference table

Recamán numbers at small indices
na(n)PreviousChange
00n/an/a
1101
2312
3633
426-4
5725
81220-8

Limits

  • Indices above 500 are rejected to keep the used set small.
  • The tool returns one term, not the full sequence up to n.
  • The sequence depends on the exact rule for revisiting values.
  • Only nonnegative indices are supported.

Common mistakes

  • Allowing subtraction to produce zero or a negative value.
  • Forgetting to check whether a value has appeared before.
  • Adding first and subtracting only as a fallback.
  • Assuming the sequence is monotonic.
  • Starting the index at one and shifting every term.

Try it yourself

Quick checks. Answers sit tucked under each question.

What is a(8)?

12, obtained by subtracting 8 from the previous term 20.

What is a(4)?

2, because 6 - 4 = 2 was unused.

What is a(3)?

6, because 3 - 3 = 0 is not positive, so 3 is added.

Questions

Who devised the sequence?

It is named after Bernardo Recamán Santos.

Why does the sequence sometimes decrease?

Because subtraction is preferred whenever the result is new and positive.

Can a value repeat?

No, the rule explicitly prevents revisiting an earlier value.

What is a(0)?

Zero, the starting point.

Is the sequence monotonic?

No, it moves up and down.

What index range is accepted?

Zero through 500.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.