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.

A383186 Inverse permutation to A383185 (square spiral numbers of king filling the two-dimensional grid always crossing the spiral's wall).

Original entry on oeis.org

0, 5, 3, 1, 10, 25, 8, 6, 19, 17, 4, 15, 13, 2, 11, 30, 28, 26, 9, 24, 22, 7, 20, 18, 43, 41, 74, 16, 14, 37, 35, 33, 12, 31, 29, 60, 58, 27, 56, 54, 23, 52, 50, 48, 21, 46, 44, 42, 79, 77, 75, 40, 73, 38, 36, 69, 67, 34, 65, 32, 63, 61, 59, 100, 98, 147, 57, 55, 94, 53, 51, 90, 88, 49, 86
Offset: 0

Views

Author

M. F. Hasler, May 12 2025

Keywords

Crossrefs

Cf. A383185.

Programs

  • Python
    def A383186(n):
        if not hasattr(A:=A383186, 'terms'): A.terms=[0]; A.N=1
        while len(t := A.terms) <= n:
           try: any(t.append(A383185.terms.index(k))for k in range(len(t), n+1))
           except: A.N = A.N*5//4+99; A383185(A.N)
        return A.terms[n]

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

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

A383187 Diamond spiral number of the n-th point visited by the king moving on the two-dimensional grid always to the earliest unvisited point on the spiral, not immediately preceding or following on the spiral.

Original entry on oeis.org

0, 2, 7, 1, 4, 11, 3, 9, 19, 8, 17, 30, 16, 6, 14, 5, 12, 23, 38, 22, 10, 20, 34, 52, 33, 18, 31, 48, 69, 47, 29, 15, 27, 43, 26, 13, 24, 39, 58, 81, 57, 37, 21, 35, 53, 75, 101, 74, 51, 32, 49, 70, 95, 124, 94, 68, 46, 28, 44, 64, 88, 63, 42, 25, 40, 59, 82, 109, 140, 108, 80, 56, 36, 54, 76
Offset: 0

Views

Author

M. F. Hasler, May 12 2025

Keywords

Comments

A permutation of the nonnegative integers, whose restriction to the positive integers is also a permutation. See A383189 for the inverse permutation.
By "king" we simply mean a cursor that can move to any of the 8 nearest (von Neumann) neighbors, as the king moves in the game of chess.
Analog of A383185 (which uses the square spiral or shells of given sup norm) for the diamond spiral (or shells of given taxicab or L1-norm) as defined, e.g., in A305258. There are less grid points having a given L1 norm, so, in this sense, the diamond spiral numbering yields a "finer" measure of the distance from the origin than the square spiral numbering.
Instead of introducing a wall that has to be crossed (as in A383185), it is here sufficient to forbid the immediately following or preceding point in order to avoid a trivial sequence (0, 1, 2, ...) of numbers.
The actual trajectory of the king is however relatively uninteresting: The resulting path consists in a clockwise square spiral (centered at (1/2, 1/2)) with transition to the next shell on the negative y-axis, cf. the "path plot" given in links.

Crossrefs

Cf. A305258 (diamond spiral), A383185 (similar for a square spiral).
Cf. A383189 (inverse permutation).

Programs

  • Python
    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 A383187(n):
        if not hasattr(A:=A383187, 'terms'): A.terms=[0]; A.pos=0; # A.track=[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:=diamond_number(A.pos+d))-A.terms[-1]) > 1 and s not in A.terms)
            A.terms.append(s); A.pos += d; # A.track.append(A.pos)
        return A.terms[n]
Showing 1-4 of 4 results.