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

A383185 Number of the square visited by a king moving on a spirally numbered board always to the lowest available unvisited square, when a wall delimiting the spiral must be crossed on each move.

Original entry on oeis.org

0, 3, 13, 2, 10, 1, 7, 21, 6, 18, 4, 14, 32, 12, 28, 11, 27, 9, 23, 8, 22, 44, 20, 40, 19, 5, 17, 37, 16, 34, 15, 33, 59, 31, 57, 30, 54, 29, 53, 85, 51, 25, 47, 24, 46, 76, 45, 75, 43, 73, 42, 70, 41, 69, 39, 67, 38, 66, 36, 62, 35, 61, 95, 60, 94, 58, 92, 56, 88, 55, 87, 127, 86, 52, 26
Offset: 0

Views

Author

M. F. Hasler, May 12 2025

Keywords

Comments

The board is numbered following a square spiral starting with 0 at the origin (where the king is at n = 0) and delimited by a wall that must be crossed on each move:
.
16 15 14 13 12 | .
,-----------. | .
17 | 4 3 2 |11 | .
| ,--- | | .
18 | 5 | 0 1 |10 | .
| '-------' | .
19 | 6 7 8 9 | .
`---------------' .
20 21 22 23 24 25
.
A line drawn from the center of the starting square to the center of the ending square must pass through a wall on each move. A move that would just touch a wall without passing through the wall (e.g., 0 to 2) is not permissible. Equivalently, the king can't move from a square labeled k to a square labeled k +- 1 or k +- 2, i.e., |a(n)-a(n+1)| > 2 for all n.
This sequence is a permutation of the nonnegative integers, see A383186 for the inverse permutation. The king's walk indeed fills the 2D grid with an initial segment S0 of 24 moves, followed by rings R(r), r >= 1, which consist of three shells S1(r), S2(r) and S3(r), each of which corresponds to a tour around the center. Each ring R(r) starts with the move number n = 48 r^2 - 16 r + 1 = (25, 147, 365, ...) to the square at position P(r) = (2-3r, 3r-3) = ((-1,0), (-4,3), (-7,6), ...), and contains a perfectly well defined sequence of 96 r + 26 grid points following a precise sequence of pattern given in full detail on the wiki page provided in the links section.

Examples

			For n = 1, a(1) = 3 because moving from 0 to 1 or 2 does not pass through a wall.
		

Crossrefs

Cf. A375925 (the same with indices and numbers of squares starting at 1).
Cf. A383186 (inverse permutation).
Cf. A316328 (knight's path), A033638, A316667 (trapped knight), A336038 (trapped king), A335856 (trapped king preferably moving to prime numbers).

Programs

  • Python
    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 A383185(n):
        if not hasattr(A:=A383185, 'terms'): A.terms=[0]; A.pos=0; A.path=[0]
        while len(A.terms) <= n:
            s,d = min((s,d) for d in (1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j) if
                abs((s:=square_number(A.pos+d))-A.terms[-1]) > 2 and s not in A.terms)
            A.terms.append(s); A.pos += d; A.path.append(A.pos)
        return A.terms[n]
    import matplotlib.pyplot as plt # this and below to plot the trajectory
    plt.plot([z.real for z in A383185.path], [z.imag for z in A383185.path])
    plt.show()

A336208 Squares visited by a knight on a square-spiral numbered board and moving to the lowest available unvisited square at each step, where the step is not in the same direction as the previous step.

Original entry on oeis.org

1, 10, 3, 6, 9, 4, 7, 2, 5, 8, 11, 14, 29, 32, 15, 12, 27, 24, 49, 52, 25, 28, 13, 34, 17, 40, 21, 46, 75, 22, 19, 16, 33, 30, 53, 26, 47, 80, 51, 48, 23, 44, 41, 18, 37, 62, 99, 36, 39, 20, 43, 70, 109, 42, 45, 74, 71, 110, 113, 72, 111, 154, 73, 108
Offset: 1

Views

Author

Scott R. Shannon, Jul 12 2020

Keywords

Comments

This is a variation of A316667. The same knight move rules apply, but at each step the knight cannot move in the same direction as its previous step.
The sequence is finite. After 217 steps the square with spiral number 118 is reached after which all surrounding squares have been visited.
The first term where this sequence differs from A316667 is a(19) = 49. The previous step was from a(17) = 27 to a(18) = 24, a step 1 unit down and 2 units to the left. The minimum unvisited spiral number one knight leap away from 24 is 45, but that is also in a direction 1 unit down and 2 units to the left, so cannot be chosen. The next closest unvisited square is 49, 1 unit down and 2 units to the right.

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 of the knight.
a(2) = 10. The eight unvisited squares one knight leap away from a(1) are numbered 10,12,14,16,18,20,22,24. Of these 10 is the lowest.
a(19) = 49. The four unvisited squares one knight leap away from a(18) = 24 are numbered 45,49,77,79. Of these 45 is the lowest but that would require a step 1 unit down and 2 units left from 24, which is the same step as a(17) = 27 to a(18) = 24, so is not allowed. The next lowest available square is 49.
		

Crossrefs

A375925 Squares visited by a king moving on a walled, spirally numbered board, where a wall must be jumped on each move, always to the lowest available unvisited square.

Original entry on oeis.org

1, 4, 14, 3, 11, 2, 8, 22, 7, 19, 5, 15, 33, 13, 29, 12, 28, 10, 24, 9, 23, 45, 21, 41, 20, 6, 18, 38, 17, 35, 16, 34, 60, 32, 58, 31, 55, 30, 54, 86, 52, 26, 48, 25, 47, 77, 46, 76, 44, 74, 43, 71, 42, 70, 40, 68, 39, 67, 37, 63, 36, 62, 96, 61, 95, 59, 93
Offset: 1

Views

Author

Sameer Khan, Sep 03 2024

Keywords

Comments

The board is numbered with the following walled, square spiral:
.
17 16 15 14 13 | .
------------- | .
18 | 5 4 3 |12 | .
| ----- | | .
19 | 6 | 1 2 |11 | .
| --------- | .
20 | 7 8 9 10 | .
----------------- .
21 22 23 24 25 26
.
The walls mark the boundary of the spiral.
A line drawn from the center of the starting square of a king move to the center of the ending square must pass through a wall. The king jumps over that wall. Some moves would just touch a wall without passing through the wall (e.g. 1 to 3). Such moves are not permissible.
The rules imply that the king cannot move from a square labeled k in the spiral to a square labeled k +- 1 or k +- 2.
Comment from M. F. Hasler, May 08 2025 (Start)
The sequence appears to be a permutation of the positive integers. The path drawn by Kevin Ryde shows the quasi-periodic structure of the trajectory and may lead to a formal proof.
However, it would be more natural to start the path at the origin, at a square labeled n = 0 (to which the king never moves). Then the sequence would conjecurally be a permutation of the nonnegative integers. This also leads to a more natural numbering for the squares in terms of the x,y coordinates - compare the Python function "square_number()". See A383185. (End) [Comment edited by N. J. A. Sloane, May 14 2025 following discussion with Kevin Ryde.]

Examples

			For n = 2, a(2) = 4 because moving to 2 or 3 does not pass through a wall.
		

Crossrefs

Cf. A033638, A316667 (trapped knight), A336038 (trapped king).
Cf. A383185 (zero-indexed variant), A316328 (knight's path).

Programs

  • Python
    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 A375925(n):
        if not hasattr(A:=A375925, 'terms'): A.terms=[1]; A.pos=0
        while len(A.terms) < n:
            s,d = min((s,d) for d in (1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j) if
                abs((s:=1+square_number(A.pos+d))-A.terms[-1]) > 2 and s not in A.terms)
            A.terms.append(s); A.pos += d
        return A.terms[n-1] # M. F. Hasler, May 07 2025

Formula

a(n) = A383185(n-1)+1. - M. F. Hasler, May 12 2025

Extensions

Entry revised by N. J. A. Sloane, May 12 2025

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-5 of 5 results.