Recaman Sequence Calculator
Find a term of Recamán's sequence, which subtracts the index when possible and adds it otherwise.
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
- Enter an index n from 0 to 500.
- Read the Recamán term in the main result box.
- Check the previous term beside it.
- A negative change means a subtraction was used.
- The default index 8 reproduces the worked example.
- Try index 4 to see the sequence drop from 6 to 2.
Formula
- 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.
- Start with a(0) = 0.
- At step 1, 0 - 1 is negative, so add: a(1) = 1.
- At step 2, 1 - 2 is negative, so add: a(2) = 3.
- At step 3, 3 - 3 is zero, so add: a(3) = 6.
- At step 4, 6 - 4 = 2 is new, so a(4) = 2.
- Continuing gives a(5) = 7, a(6) = 13 and a(7) = 20.
- At step 8, 20 - 8 = 12 is new, so a(8) = 12.
- The tool reports 12, previous term 20, and change -8.
Reference table
| n | a(n) | Previous | Change |
|---|---|---|---|
| 0 | 0 | n/a | n/a |
| 1 | 1 | 0 | 1 |
| 2 | 3 | 1 | 2 |
| 3 | 6 | 3 | 3 |
| 4 | 2 | 6 | -4 |
| 5 | 7 | 2 | 5 |
| 8 | 12 | 20 | -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.