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.

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()

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.

A383183 Square spiral numbers of the n-th grid point 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, 5, 7, 23, 47, 79, 48, 24, 8, 1, 11, 13, 31, 29, 53, 27, 9, 10, 26, 25, 49, 83, 50, 51, 52, 28, 12, 30, 54, 55, 89, 131, 179, 129, 87, 127, 85, 84, 124, 173, 229, 293, 227, 169, 223, 167, 119, 80, 81, 82, 122, 120, 121, 168, 170, 171, 123, 172, 228, 292, 226, 224, 225, 287, 359, 439
Offset: 0

Views

Author

M. F. Hasler, May 13 2025

Keywords

Comments

The infinite 2D grid is labeled along a square spiral as shown in A316328, starting with 0 at the origin (0,0), where the n-th shell contains the 8n points with sup norm n, as follows:
.
16--15--14--13--12 :
| | :
17 4---3---2 11 28
| | | | |
18 5 0---1 10 27
| | | |
19 6---7---8---9 26
| |
20--21--22--23--24--25
.
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 171th move, the cursor is trapped in the point (3,0) labeled a(171) = 33. All eight neighbors were then already visited earlier, so the king has no more any possible move.

Examples

			From the starting point (0,0) labeled a(0) = 0, the king can reach the point (1,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,0) labeled 5 = a(3), and then to (0,-1) labeled a(4) 7 = a(4). From there, the only available prime number is 23 = a(5) at (1,-2).
The king continues in that south-east direction, before walking in north-east direction and then back and further south-east up to and beyond the point (10,-10). Then it goes back in the opposite north-west direction up to (-8,7) and (-5, 8), before heading to the point (3,0) where it gets stuck.
		

Crossrefs

Cf. A383184 (the same with "diamond spiral" numbering).
Cf. A383185 (similar with |a(n)-a(n+1)| > 2 instead of the prime number condition).
Cf. A335856 (same with the square spiral and indices starting at 1).
Cf. A316328 (knight path on square spiral numbered board).

Programs

  • Python
    from sympy import isprime # = 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 A383183(n, moves=(1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)):
        if not hasattr(A:=A383183, '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 := square_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]
    A383183(999) # gives IndexError: Sequence has only 172 terms
    A383183.terms # shows the full sequence; append [:N] to show only N terms
    import matplotlib.pyplot as plt # this and following to plot the path:
    plt.plot([z.real for z in A383183.path], [z.imag for z in A383183.path])
    plt.show()

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.
Showing 1-4 of 4 results.