A335856 Squares visited by a chess king on a spirally numbered infinite board where the king moves to the adjacent unvisited square containing the lowest prime number. If no such square is available it chooses the lowest-numbered adjacent unvisited square.
1, 2, 3, 11, 29, 13, 31, 59, 32, 14, 4, 5, 17, 37, 67, 103, 149, 104, 66, 38, 18, 19, 7, 23, 47, 79, 48, 24, 8, 6, 20, 41, 71, 43, 73, 109, 72, 42, 21, 22, 44, 45, 46, 76, 75, 113, 74, 112, 110, 111, 157, 211, 271, 209, 269, 337, 267, 205, 151, 107, 69, 39, 40, 68, 105, 106, 70, 108
Offset: 1
Examples
The board is numbered with the square spiral: . 17--16--15--14--13 . | | . 18 5---4---3 12 29 | | | | | 19 6 1---2 11 28 | | | | 20 7---8---9--10 27 | | 21--22--23--24--25--26 . a(1) = 1, the starting square for the king. a(2) = 2. The four unvisited squares around a(1) the king can move which contain prime numbers are 2,3,5,7. Of those 2 is the lowest. a(4) = 11. The two unvisited squares around a(3) = 3 the king can move to which contain prime numbers are 11 and 13. Of those 11 is the lowest. a(9) = 32. There are no unvisited squares around a(8) = 59 which contain prime numbers. The seven other unvisited squares are numbered 32,33,58,60,93,94,95. Of those 32 is the lowest.
Links
- M. F. Hasler, Table of n, a(n) for n = 1..720 (complete sequence), May 13 2025
- Scott R. Shannon, Image showing the 719 steps of the path. A green dot marks the starting square and a red dot the final square with number 437. The red dot is surrounded by eight blue dots to show the occupied neighboring squares. A yellow dot marks the smallest unvisited square with number 33.
Crossrefs
Programs
-
Python
from sympy import isprime # or use A010051 def square_number(z): return int(4*y**2-y-x if (y := z.imag) >= abs(x := z.real) else 4*x**2-x-y if -x>=abs(y) else (4*y-3)*y+x if -y>=abs(x) else (4*x-3)*x+y) def A335856(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)): if not hasattr(A:=A335856, 'terms'): A.terms=[1]; A.pos=0 while len(A.terms) < n: try: move = min((1-isprime(s), s, z) for d in moves if (s := square_number(z := A.pos+d)+1)not in A.terms) except ValueError: raise IndexError(f"Sequence has only {len(A.terms)} terms") A.terms.append(move[1]); A.pos = move[2] return A.terms[n-1] A335856(999) # gives IndexError: Sequence has only 720 terms A335856.terms # shows all 720 terms; append [:N] to see only N terms # M. F. Hasler, May 13 2025
Extensions
Name edited by Peter Munn, May 11 2025
More terms (complete sequence) from M. F. Hasler, May 13 2025
Comments