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-4 of 4 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

A336494 The number of steps for a walk on a square spiral numbered board when starting on square 1 and stepping to an unvisited square containing the lowest prime number, where the square is within a block of size (2n+1) X (2n+1) centered on the current square. If no unvisited prime numbered squares exist within the block the walk ends.

Original entry on oeis.org

7, 37, 65, 308, 654, 7214, 21992, 49850, 222791, 1146922, 1912101, 6372680, 23077800
Offset: 1

Views

Author

Scott R. Shannon, Jul 23 2020

Keywords

Comments

For n = 1 this sequence is similar to A335856 except that only prime numbers can be stepped to; if no adjacent prime number exists then the walk ends. In general for a(n) the walk can step to any unvisited square containing the lowest prime number within a block of size (2n+1) X (2n+1) centered on the current square.
See A336576 for the final square number of the walks.

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) = 7. Starting from the square 1 the sequence of adjacent unvisited lowest primes the walk can step to are 2,3,11,29,13,31,59. Once the square 59 is visited there are no other unvisited adjacent squares containing primes, so the walk terminates after 7 steps. See the first linked image.
a(2) = 38. This walk also starts by stepping to 2 and then 3. But the next lowest prime 5 is now two units away so is reachable and is thus the next stepped to square. Further steps are 7,19,17,37...,827,829,719,947. Once the square 947 is visited there are no other unvisited squares containing primes within the surrounding 5x5 block of squares, so the walk terminates after 38 steps. See the second linked image.
Also see the linked images for n=3,4,5,6.
		

Crossrefs

Cf. A336576 (final square number), A335856, A000040, A136626, A336092, A330979, A332767, A335661, A335364.

A336576 The final square number for a walk on a square spiral numbered board when starting on square 1 and stepping to an unvisited square containing the lowest prime number, where the square is within a block of size (2n+1) x (2n+1) centered on the current square. If no unvisited prime numbered squares exist within the block the walk ends.

Original entry on oeis.org

59, 947, 313, 3331, 5659, 67547, 253801, 676259, 3162413, 16604417, 29135971, 108235159, 437456497
Offset: 1

Views

Author

Scott R. Shannon, Jul 26 2020

Keywords

Comments

See A336494 for an explanation of the sequence and images of the walks.

Examples

			a(1) = 59. Starting from the square 1 the sequence of adjacent unvisited lowest primes the walk can step to are 2,3,11,29,13,31,59. Once the square 59 is visited there are no other unvisited adjacent squares containing primes, so the walk terminates.
		

Crossrefs

Cf. A336494 (total number of steps), A335856, A000040, A136626, A336092, A330979, A332767, A335661, A335364.

A335900 Squares visited by a fairy chess wazir moving on a square-spiral numbered board where the wazir moves to the unvisited square containing the spiral number with the fewest divisors. In case of a tie it chooses the square with the lowest spiral number.

Original entry on oeis.org

1, 2, 3, 4, 5, 6, 7, 8, 23, 22, 21, 20, 19, 18, 17, 38, 37, 64, 65, 66, 67, 68, 39, 40, 41, 42, 43, 74, 73, 110, 109, 154, 155, 208, 269, 268, 337, 338, 339, 340, 271, 272, 211, 274, 275, 346, 347, 426, 427, 514, 515, 428, 349, 278, 277, 214, 159, 158, 157, 212, 213, 276
Offset: 1

Views

Author

Scott R. Shannon, Jun 29 2020

Keywords

Comments

A fairy chess wazir can move one step in each of the four orthogonal grid directions, i.e., the same directions as a chess rook but only one square. In this sequence the wazir moves to the closest unvisited neighboring square which contains the number with the fewest divisors, and in case of a tie the square with the lowest spiral number. Note that if the wazir simply moves to the lowest available number the sequence will be infinite as the wazir will just follow the square spiral path.
The sequence is finite. After 61 steps the square with number 276 is visited, after which all four neighboring squares have been visited.
Due to the wazir's preference for squares with the fewest divisors it will move to a prime numbered square when possible, and the lowest prime if two or more unvisited primes are in neighboring squares. Of the 61 visited squares, 21 contain prime numbers, while 40 contain composites. The largest visited square is a(51) = 515.

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 wazir.
a(2) = 2. The four unvisited squares around a(1) to which the wazir can move are numbered 2,4,6,8. Of these, 2 has only two divisors, so it is the square chosen.
a(9) = 23. The two unvisited squares around a(8) = 8 to which the wazir can move are numbered 9 and 23. Of these, 23 has only two divisors, so it is the square chosen.
		

Crossrefs

Showing 1-4 of 4 results.