# Recamán's sequence

In mathematics and computer science, the Recamán's sequence[1][2] (or Recaman's sequence) is a well known sequence defined by a recurrence relation, because its elements are related to the previous elements in a straightforward way are often defined using recursion.

A drawing of the first 75 terms of the Recamán's sequence[3], according with the method of visualization shown in the Numberphile video The Slightly Spooky Recamán Sequence[4]

It takes its name after its inventor Bernardo Recamán Santos (Bogotá, August 5, 1954), a Colombian mathematician.

## Definition

The Recamán's sequence ${\displaystyle a_{0},a_{1},a_{2}\dots }$  is defined as:

${\displaystyle a_{n}={\begin{cases}0&&{\text{if }}n=0\\a_{n-1}-n&&{\text{if }}a_{n-1}-n>0{\text{ and is not already in the sequence}}\\a_{n-1}+n&&{\text{otherwise}}\end{cases}}}$

The first terms of the sequence are:

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155, ...

## On-line encyclopedia of integer sequences (OEIS)

Recamán's sequence was named after its inventor, Colombian mathematician Bernardo Recamán Santos, by Neil Sloane, creator of the On-Line Encyclopedia of Integer Sequences (OEIS). The OEIS entry for this sequence is A005132.

Even when Neil Sloane has collected more than 325,000 sequences since 1964, the Recamán's sequence was referenced in his paper My favorite integer sequences.[5] He also stated that of all the sequences in the OEIS, this one is his favorite to listen to[1] (you can hear it below).

## Visual representation

A plot for the first 200 terms of the Recáman's sequence.[3]

The most-common visualization of the Recamán's sequence is simply plotting its values, such as the figure at right.

On January 14, 2018, the Numberphile YouTube channel published a video titled The Slightly Spooky Recamán Sequence[4], showing a visualization using alternating semi-circles, as it is shown in the figure at top of this page.

On January 25, 2018, Benjamin Chaffin[6] published a log–log plot to visualize the first 10230 terms of the Recamán's sequence.[7]

## Sound representation

Values of the sequence can be associated with musical notes, in such that case the running of the sequence can be associated with an execution of a musical tune.[8]

## Properties

The sequence satisfies[1]:

${\displaystyle a_{n}\geq 0}$
${\displaystyle |a_{n}-a_{n-1}|=n}$

This is not a permutation of the integers: the first repeated term is ${\displaystyle 42=a_{24}=a_{20}}$ .[9] Another one is ${\displaystyle 43=a_{18}=a_{26}}$ .

### Conjectures

Neil Sloane has conjectured that every number eventually appears,[10][11][12] but it has not been proved. Even though 10230 terms have been calculated (in 2018), the number 852,655 has not appeared on the list.[1]

### Uses

Besides its mathematical and aesthetic properties, Recamán's sequence can be used to secure 2D images by steganography.[13]

## Programming

The calculation of terms of the sequence can be programmed.

The wiki-based programming chrestomathy website Rosetta Code, in its page Recaman's sequence collects a series of programs in 30+ different programming languages for calculation of terms of the sequence.[14]

## Alternate sequence

The sequence is the most-known sequence invented by Recamán. There is another sequence, less known, defined as:

${\displaystyle a_{1}=1}$
${\displaystyle a_{n+1}={\begin{cases}a_{n}/n&&{\text{if }}n{\text{ divides }}a_{n}\\na_{n}&&{\text{otherwise}}\end{cases}}}$

This OEIS entry is A008336.

## References

1. ^ a b c d https://oeis.org/A005132
2. ^ http://mathworld.wolfram.com/RecamansSequence.html
3. ^ a b Recaman's sequence. A solution to the task Recaman's sequence in the Rosetta Code, written in Fōrmulæ. The Fōrmulæ wiki. Retrieved September 24, 2019.
4. ^ a b The Slightly Spooky Recamán Sequence, Numberphile video.
5. ^ N. J. A. Sloane, Sequences and their Applications (Proceedings of SETA '98), C. Ding, T. Helleseth and H. Niederreiter (editors), Springer-Verlag, London, 1999, pp. 103–130.
6. ^ https://oeis.org/wiki/User:Benjamin_Chaffin
7. ^ https://oeis.org/A005132/a005132.png
8. ^ https://oeis.org/play?seq=A005132
9. ^ Math less traveled
10. ^ https://oeis.org/A057167
11. ^ https://oeis.org/A064227
12. ^ https://oeis.org/A064228
13. ^ S. Farrag and W. Alexan, "Secure 2D Image Steganography Using Recamán's Sequence," 2019 International Conference on Advanced Communication Technologies and Networking (CommNet), Rabat, Morocco, 2019, pp. 1-6. doi: 10.1109/COMMNET.2019.8742368
14. ^ http://rosettacode.org/wiki/Recaman%27s_sequence