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

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