cp's OEIS Frontend

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.

Showing 1-2 of 2 results.

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.

Original entry on oeis.org

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

Views

Author

Scott R. Shannon, Jun 27 2020

Keywords

Comments

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.
The sequence is finite. After 719 steps the square with number 437 is visited, after which all adjacent neighboring squares have been visited.
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.
The largest visited square is a(709) = 1367. The lowest unvisited square is 33.
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
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

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.
		

Crossrefs

Cf. A000040 (the primes), A010051 (characteristic function of the primes).

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

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.

Original entry on oeis.org

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

Views

Author

M. F. Hasler, May 13 2025

Keywords

Comments

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:
. (y)
2 | 8 17
| / \ \
1 | 9 2 7 16
| / / \ \ \
0 | 10 3 0--1 6 15
| \ \ / /
-1 | 11 4--5 14
| \ /
-2 | 12--13
x: -2 -1 0 1 2 3
.
(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.)
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.
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.

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.
		

Crossrefs

Cf. A383183 (same with square spiral numbering).
Cf. A305258 (more details about the diamond spiral).

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()
Showing 1-2 of 2 results.