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). It is a well known sequence defined by a recurrence relation. In computer science they are often defined by recursion.
The sequence satisfies This is not a permutation of the integers: the first repeated term is Another one is Neil Sloane has conjectured that every number eventually appears, but it has not been proved. Even though 1015 terms have been calculated (in 2018), the number 852,655 has not appeared on the list.
MATLAB CODE FOR Recamán Sequence
n=65; % Number of Terms in the Sequence
A = zeros(1,n);
A(1) = 0;
for ii = 1:n-1 % Algorithm to create the sequence
b = A(ii)-ii;
A(ii+1) = b + 2*ii;
if b > 0 && ~any(A == b)
A(ii + 1) = b;
end
end
hold on;
axis equal;
for i = 2:1:n % Plotting the Graphs
y = 0; x = (A(i)+A(i-1))/2; r = (A(i)-A(i-1))/2;
th = 0:pi/50:pi;
if A(i)>A(i-1)
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
end
if A(i)<A(i-1)
xunit = -r * cos(th) + x;
yunit = -r * sin(th) + y;
end
if mod(i,2) == 0
h = plot(xunit, -yunit,'k');
else
h = plot(xunit, yunit,'k');
end
end