• Remix
  • Share
  • New Entry

  • Eugen Prel

  • /
  • Recamán's sequence (illustrated with spiraling squares)

on 28 Oct 2021
  • 6
  • 26
  • 1
  • 0
  • 277
n=500;
s=zeros(1,3*n);
z=-1;
c=bone(n);
figure('Color',[.16 .16 .2]);
hold; axis off equal;
Current plot held
for i=1:n-1
t=s(i)-i;
for j=1:i+1
if s(j)==t||t<0
t=s(i)+i;
break;
end
end
s(i+1)=t;
y=z^i*abs(s(i+1)-s(i))/2;
line(s(i)*[1,1],[0,y],'Col',c(i,:));
line([s(i),t],[y,y],'Col',c(i,:));
line([t,t],[y,0],'Col',c(i,:));
end
Remix Tree