Recamán's sequence

In mathematics and computer science, Recamán'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, they are often defined using recursion.



It takes its name after its inventor Bernardo Recamán Santos, a Colombian mathematician.

Definition
Recamán's sequence $$a_0, a_1, a_2\dots$$ is defined as:


 * $$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.

Visual representation


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, showing a visualization using alternating semi-circles, as it is shown in the figure at top of this page.

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.

Properties
The sequence satisfies:


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

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

Conjecture
Neil Sloane has conjectured that every number eventually appears,  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.

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

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


 * $$a_1 = 1$$
 * $$a_{n + 1} = \begin{cases}

a_n / n && \text{if } n \text{ divides } a_n \\ n a_n && \text{otherwise} \end{cases}$$

This OEIS entry is.