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 A383184 #8 May 24 2025 17:53:58 %S A383184 0,2,3,11,23,4,5,13,12,24,41,61,40,59,83,60,84,113,85,86,62,25,26,43, %T A383184 14,1,7,17,31,8,19,9,10,37,21,20,53,34,33,18,32,71,97,127,72,73,50,49, %U A383184 48,47,29,6,15,16,30,69,68,67,28,27,44,89,64,63,42,87,88,149,116,115,114,146,223,182,181,144,179,112,111,110,109,58,38,22,57,56,79,107,139,80,81,82,39 %N A383184 Diamond spiral numbers of the grid points visited by a king always moving to the unvisited point labeled with the smallest possible prime or else composite number. %C A383184 The infinite 2D grid is labeled along a diamond spiral as shown in A305258, starting with 0 at the origin (0,0), where each "shell" contains the points with given taxicab or L1-norm, as follows: %C A383184 . (y) %C A383184 2 | 8 17 %C A383184 | / \ \ %C A383184 1 | 9 2 7 16 %C A383184 | / / \ \ \ %C A383184 0 | 10 3 0--1 6 15 %C A383184 | \ \ / / %C A383184 -1 | 11 4--5 14 %C A383184 | \ / %C A383184 -2 | 12--13 %C A383184 |_____________________ %C A383184 x: -2 -1 0 1 2 3 %C A383184 . %C A383184 (This numbering, where the n-th "shell" has only 4n numbers, is "finer" than the square spiral numbering where the n-th shell has 8n numbers.) %C A383184 The cursor is moving like a chess king to the von Neumann neighbor not visited earlier and labeled with the smallest prime number if possible, otherwise with the smallest possible composite number. %C A383184 After the 92th move, the cursor is trapped in the point (-1,-3) labeled a(92) = 39. All eight neighbors were then already visited earlier, so the king has no more any possible move: see the "path plot" given in the links section. %H A383184 M. F. Hasler, <a href="/A383184/a383184.png">Path plot of A383184(0..92)</a>. (Dark blue points represent the 8 neighbors already visited around the red end point (-1,-3).) %e A383184 From the starting point (0,0) labeled a(0) = 0, the king can reach the point (0,1) labeled 2, which is the smallest possible prime number, so a(1) = 2. %e A383184 Then the king can reach (-1,0) labeled 3 which is the next smaller prime number, so a(2) = 3. From there it can go to (-1,-1) labeled 11 = a(3), and so on. %e A383184 The king reaches (1,7) and (1,-9) before getting trapped at (-1,-3) from where there is no more any unvisited point among the 8 neighbors. %o A383184 (Python) %o A383184 from sympy import isprime %o A383184 def diamond_number(z): %o A383184 x, y = int(z.real), int(z.imag); d = abs(x)+abs(y) %o A383184 return 2*d*(d-1)+((x if y<0 else d+y)if x>0 else 2*d-x if y>0 else 3*d-y) %o A383184 def A383184(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)): %o A383184 if not hasattr(A:=A383184, 'terms'): A.terms=[0]; A.pos=0; A.path=[0] %o A383184 while len(A.terms) <= n: %o A383184 try: _,s,z = min((1-isprime(s), s, z) for d in moves if %o A383184 (s := diamond_number(z := A.pos+d))not in A.terms) %o A383184 except ValueError: %o A383184 raise IndexError(f"Sequence has only {len(A.terms)} terms") %o A383184 A.terms.append(s); A.pos = z; A.path.append(z) %o A383184 return A.terms[n] %o A383184 A383184(999) # gives IndexError: Sequence has only 93 terms %o A383184 A383184.terms # shows the full sequence %o A383184 import matplotlib.pyplot as plt # this and following to plot the path: %o A383184 plt.plot([z.real for z in A383184.path], [z.imag for z in A383184.path]) %o A383184 plt.show() %Y A383184 Cf. A383183 (same with square spiral numbering). %Y A383184 Cf. A305258 (more details about the diamond spiral). %K A383184 nonn,walk,fini,full %O A383184 0,2 %A A383184 _M. F. Hasler_, May 13 2025