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 A335856 #31 May 18 2025 23:48:21 %S A335856 1,2,3,11,29,13,31,59,32,14,4,5,17,37,67,103,149,104,66,38,18,19,7,23, %T A335856 47,79,48,24,8,6,20,41,71,43,73,109,72,42,21,22,44,45,46,76,75,113,74, %U A335856 112,110,111,157,211,271,209,269,337,267,205,151,107,69,39,40,68,105,106,70,108 %N 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. %C A335856 This sequences gives the numbers of the squares visited by a chess king moving on a square-spiral numbered board where the king starts on the 1 numbered square and at each step moves to the adjacent unvisited square containing the lowest prime number. If no adjacent unvisited square contains a prime number then the square with the lowest spiral number is chosen. Note that if the king simply moves to the lowest unvisited number the sequence will be infinite as the king will just follow the square spiral path. %C A335856 The sequence is finite. After 719 steps the square with number 437 is visited, after which all adjacent neighboring squares have been visited. %C A335856 Of the 719 visited squares 165 contain prime numbers while 554 contain composites. As the odd numbers are diagonally adjacent in the square spiral the king's path will contain many diagonal steps, often taking numerous diagonal steps is succession - see the attached link image. %C A335856 The largest visited square is a(709) = 1367. The lowest unvisited square is 33. %C A335856 The 719 steps until self-trapping occurs are significantly larger than the expected average of 210 moves to self-trapping for a random walk of the king on an infinite chessboard. See the link to the probability density graphs in A323562. - _Hugo Pfoertner_, Jul 19 2020 %C A335856 When the grid points are labeled starting with 0 at the origin, the king gets trapped after 171 moves at (3,0), after going as far as (10,-11) to the south-east and (-8,7) and (-5,8) to the north-east, see A383183. - _M. F. Hasler_, May 13 2025 %H A335856 M. F. Hasler, <a href="/A335856/b335856.txt">Table of n, a(n) for n = 1..720</a> (complete sequence), May 13 2025 %H A335856 Scott R. Shannon, <a href="/A335856/a335856.png">Image showing the 719 steps of the path</a>. 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. %e A335856 The board is numbered with the square spiral: %e A335856 . %e A335856 17--16--15--14--13 . %e A335856 | | . %e A335856 18 5---4---3 12 29 %e A335856 | | | | | %e A335856 19 6 1---2 11 28 %e A335856 | | | | %e A335856 20 7---8---9--10 27 %e A335856 | | %e A335856 21--22--23--24--25--26 %e A335856 . %e A335856 a(1) = 1, the starting square for the king. %e A335856 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. %e A335856 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. %e A335856 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. %o A335856 (Python) %o A335856 from sympy import isprime # or use A010051 %o A335856 def square_number(z): return int(4*y**2-y-x if (y := z.imag) >= abs(x := z.real) %o A335856 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) %o A335856 def A335856(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)): %o A335856 if not hasattr(A:=A335856, 'terms'): A.terms=[1]; A.pos=0 %o A335856 while len(A.terms) < n: %o A335856 try: move = min((1-isprime(s), s, z) for d in moves if %o A335856 (s := square_number(z := A.pos+d)+1)not in A.terms) %o A335856 except ValueError: %o A335856 raise IndexError(f"Sequence has only {len(A.terms)} terms") %o A335856 A.terms.append(move[1]); A.pos = move[2] %o A335856 return A.terms[n-1] %o A335856 A335856(999) # gives IndexError: Sequence has only 720 terms %o A335856 A335856.terms # shows all 720 terms; append [:N] to see only N terms %o A335856 # _M. F. Hasler_, May 13 2025 %Y A335856 Cf. A333714, A333713, A335816, A336038, A336092, A316667. %Y A335856 Cf. A174344, A274923, A272763, A323561, A323562. %Y A335856 Cf. A000040 (the primes), A010051 (characteristic function of the primes). %K A335856 nonn,walk,fini,full %O A335856 1,2 %A A335856 _Scott R. Shannon_, Jun 27 2020 %E A335856 Name edited by _Peter Munn_, May 11 2025 %E A335856 More terms (complete sequence) from _M. F. Hasler_, May 13 2025