Recamán Sequence Term
Return a(0)=0 and a(n)=a(n−1)−n when that value is positive and unused, otherwise a(n−1)+n; the index is capped at 100,000.
Description
Recamán’s sequence uses a subtraction whenever it reaches a positive value not previously seen, and addition otherwise.
Recamán’s sequence uses a subtraction whenever it reaches a positive value not previously seen, and addition otherwise. The history of visited values is part of the recurrence.1
The tool returns value. The indexing and output conventions below determine how to read these values.
When to use Recamán Sequence Term
Use this for the following task: Return a(0)=0 and a(n)=a(n−1)−n when that value is positive and unused, otherwise a(n−1)+n; the index is capped at 100,000. Use the input and output conventions below to reproduce the intended mathematical quantity.
How to use Recamán Sequence Term and understand its results
- Choose the required indexes, integers or sequence entries. Preserve decimal-string encodings where the field table specifies strings.
- Enter n according to the field table, then run the tool.
- Read value. Use the stated units, indexing and interpretation of the numerical result.
- Keep exact decimal strings for subsequent integer arithmetic; distinguish them from any explicitly approximate numeric result.
| Input field | Meaning | Value type and bounds | Requirement |
|---|---|---|---|
| n | Zero-indexed term (resource limit 100000) | integer; minimum 0; maximum 100000 | Required |
Track a set initialized with zero. At each step choose the allowed subtraction or fall back to addition and record the resulting value.
a(0)=0; a(n)=a(n−1)−n if positive and unused, otherwise a(n−1)+n The symbols and boundary conditions refer to the supplied fields and the implementation described above.
| Output field | Meaning | Value type |
|---|---|---|
| value | Recamán sequence term | integer |
{
"input": {
"n": 10
},
"output": {
"value": 11
}
} Limitations and assumptions
The zero-based index is at most 100000. Addition may revisit a prior value, so the rule does not make the whole sequence duplicate-free.
Use the declared integer bounds and string formats. Large exact outputs remain decimal strings; numerical approximations use ordinary floating-point arithmetic. A rejected input is different from a valid zero count or false membership flag.
Alternative or Complementary methods
Choose nth Tribonacci Number when you need its operation: Return T(n) exactly with T(0)=T(1)=0, T(2)=1, and each later term the sum of the preceding three; the index is capped at 10,000. Choose Lucky Number Checker for the complementary operation: Test membership in the lucky-number sieve that starts with positive odd integers and repeatedly removes every kth survivor; input is capped at 100,000.
Background reference: OEIS A005132.
References
-
OEIS A005132 — OEIS Foundation
Similar or alternative tools
- nth Tribonacci Number
Return T(n) exactly with T(0)=T(1)=0, T(2)=1, and each later term the sum of the preceding three; the index is capped at 10,000.
- Lucky Number Checker
Test membership in the lucky-number sieve that starts with positive odd integers and repeatedly removes every kth survivor; input is capped at 100,000.