This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A327439 #27 Dec 17 2024 22:54:15 %S A327439 1,3,2,1,3,2,5,4,9,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,3, %T A327439 2,5,4,9,13,12,11,10,9,8,7,6,5,4,3,2,1,3,2,5,4,7,6,9,8,11,23,22,21,20, %U A327439 19,18,17,16,15,14,13,12,11 %N A327439 a(0)=1. If a(n-1) and n are relatively prime and a(n-1)!=1, a(n) = a(n-1) - 1. Otherwise (i.e., if a(n-1) and n share a common factor or a(n-1)=1), a(n) = a(n-1) + gcd(a(n-1),n) + 1. %C A327439 Graphically at large scales this sequence is vaguely self-similar, though in certain sections it acts in a rough manner, in particular in regions surrounding apparent cusps. See the program for a graph to zoom in on these sections. %C A327439 See Python program for zoomable graph. %H A327439 Nathaniel J. Strout, <a href="/A327439/b327439.txt">Table of n, a(n) for n = 0..116000</a> %t A327439 a[0] = 1; a[n_] := a[n] = If[a[n - 1] != 1 && CoprimeQ[n, a[n - 1]], a[n - 1] - 1, a[n - 1] + GCD[a[n - 1], n] + 1]; Array[a, 101, 0] (* _Amiram Eldar_, Feb 24 2020 *) %t A327439 nxt[{n_,a_}]:={n+1,If[CoprimeQ[n+1,a]&&a!=1,a-1,a+GCD[a,n+1]+1]}; NestList[nxt,{0,1},70][[;;,2]] (* _Harvey P. Dale_, Jun 08 2024 *) %o A327439 (Python) %o A327439 import math %o A327439 import matplotlib.pyplot as plt %o A327439 num = 10000 %o A327439 x = [] %o A327439 y = [] %o A327439 # y is the main sequence %o A327439 def sequence(): %o A327439 a = 1 %o A327439 y.append(a) %o A327439 for i in range(num): %o A327439 if (a != 1) and (math.gcd(a,i+1) == 1): %o A327439 a -= 1 %o A327439 else: %o A327439 a += math.gcd(a,i+1)+1 %o A327439 x.append(i) %o A327439 y.append(a) %o A327439 x.append(num) %o A327439 sequence() %o A327439 # code only regarding the plot. %o A327439 plt.xlim(0,num) %o A327439 plt.ylim(0,num) %o A327439 plt.plot(x, y) %o A327439 plt.xlabel('x - axis') %o A327439 plt.ylabel('y - axis') %o A327439 plt.title('Plot of Sequence') %o A327439 plt.show() %K A327439 nonn,look %O A327439 0,2 %A A327439 _Nathaniel J. Strout_, Feb 24 2020