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.
0, 2, 3, 11, 23, 4, 5, 13, 12, 24, 41, 61, 40, 59, 83, 60, 84, 113, 85, 86, 62, 25, 26, 43, 14, 1, 7, 17, 31, 8, 19, 9, 10, 37, 21, 20, 53, 34, 33, 18, 32, 71, 97, 127, 72, 73, 50, 49, 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
Offset: 0
Examples
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. 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. 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.
Links
- M. F. Hasler, Path plot of A383184(0..92). (Dark blue points represent the 8 neighbors already visited around the red end point (-1,-3).)
Crossrefs
Programs
-
Python
from sympy import isprime def diamond_number(z): x, y = int(z.real), int(z.imag); d = abs(x)+abs(y) 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) def A383184(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)): if not hasattr(A:=A383184, 'terms'): A.terms=[0]; A.pos=0; A.path=[0] while len(A.terms) <= n: try: _,s,z = min((1-isprime(s), s, z) for d in moves if (s := diamond_number(z := A.pos+d))not in A.terms) except ValueError: raise IndexError(f"Sequence has only {len(A.terms)} terms") A.terms.append(s); A.pos = z; A.path.append(z) return A.terms[n] A383184(999) # gives IndexError: Sequence has only 93 terms A383184.terms # shows the full sequence import matplotlib.pyplot as plt # this and following to plot the path: plt.plot([z.real for z in A383184.path], [z.imag for z in A383184.path]) plt.show()
Comments