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.

A383190 a(2n) and a(2n+1) are the square spiral numbers of the position on which the (n+1)th domino is placed, when tiling the plane by placing the dominos always as near as possible to the origin and so that no two dominos share a long side. Inverse permutation of A383191.

Original entry on oeis.org

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

Views

Author

M. F. Hasler, Apr 18 2025

Keywords

Comments

"As near as possible to the origin" means that one end of the domino is placed on the free grid point nearest to the origin for the Euclidean distance, and in case of a tie, earliest counter-clockwise, starting to the right. (I.e., on the complex plane, the lexico-earliest (|z|, arg z) with 0 <= arg z < tau = 6.283185...) The other end of the domino will be placed on a free grid point to the north, south, east or west of the first end, also nearest possible to the origin, but so that the domino is not side-by-side sharing a long side with another domino. Each domino is represented by two consecutive integers (2n, 2n+1): (0, 1), (2, 3), etc.
The sequence is obtained by listing the "square spiral number" (cf. A316328) corresponding to the position of the number n (i.e., the first half of the (n/2+1)th domino for even n, and the second half of the (n+1)/2-th domino for odd n.
This sequence is a permutation of the nonnegative integers.
The inverse permutation A383191 is obtained by reading these integers along the plane filling square spiral, starting at the origin, then one step to the right, then one step up, etc.

Examples

			The first domino (0, 1) is placed on the origin and the square to its right.
The second domino (2, 3) is placed above the origin (nearest free point coming first counter-clockwise), oriented to the left (since going to the right would make it side-by-side with the first domino, which is forbidden).
Then the third domino (4, 5) is placed left to the origin, going downwards (using the free point closest to the origin).
The fourth domino (6, 7) is placed below the origin, going downwards (since going to the right would make it parallel to the first domino).
Then the free points nearest to the origin are to its lower right and to its upper right. The upper right is preferred since it comes first counter-clockwise (starting to the right). The domino (8, 9) is placed sidewards, again because the other end upwards) would come later in counter-clockwise sense.
Then the domino (10, 11) is placed to the lower right, also sideways because vertically it would be side-by-side with (6, 7).
The first 16 dominoes are placed as follows, where the numbers (2n-2, 2n-1) represent the two ends of the n-th domino, and t
|
|    19==18  14==15  26==27
|
|    17   3===2   8===9           The sequence is obtained by listing the square
|    ||                           spiral number corresponding to the position of
|    16   4   0===1  12==13       the numbers 0, 1, 2, 3...: 0 for 0, 1 for 1,
|         ‖                       3 (square spiral number for position (x=0, y=1)
|    20   5   6  10==11           where 2 is placed, 4 for the position of 3,
|    ||       ‖                   5, 6, 7 for the position of 4, 5, 6; then
|    21  22   7  24  28==29       22 for the position (x=0, y=-2) of 7, 2 for 8, ...
|        ||      ||
|        23      25
|
We see that all dominoes in the upper right half plane are placed horizontally, and in the lower left half they are placed vertically.
		

Crossrefs

Cf. A383191 (inverse permutation), A316328 (knight tour with illustration of the square spiral), A174344 (square spiral, but clockwise).

Programs

  • Python
    class A383190: # use A383190(n) or a=A383190(); a[n]; print(a); for x in a: ...
        border, grid, terms = {0}, {}, []
        neighbors = (1, 1+1j, 1j, 1j-1, -1, -1-1j, -1j, 1-1j)
        def _str_(self): #"ASCII representation of (filled part of) the plane."
            X = sorted({z.real for z in self.grid}); L = len(str(len(self.terms)))+1
            return "\n".join("".join(f"{self.grid.get(x+y*1j,'')!s:{L}}" for x in X)
                             for y in sorted({z.imag for z in self.grid}, reverse=1))
        def _new_(cls, n: int | None = None) -> int | object:
            """Return a(n) or the sequence object if no n is given."""
            return super()._new_(cls) if n is None else super()._new_(cls)(n)
        def _call_(self, n: int | None = None) -> int | object:
            """Return a(n) or the sequence object if no n is given."""
            return self if n is None else self.extend(upto=n) or self.terms[n]
        def _getitem_(self, n: int | slice) -> int | list:
            return self(n) if isinstance(n, int) else [self(n) for n in
                range(*n.indices(max(len(self.terms), abs(n.stop or 0))))]
        def extend(self, upto=None):
            "Place new domino(s) on the grid, as 'close' as possible to the origin."
            while len(self.terms) <= (upto or (upto := len(self.terms))):
                self.fill(pos := min(self.border, key = self.distance))
                self.fill(self.second(pos))
        def distance(self, pos):
            "Return (abs(pos), arg(pos)), where 0 <= arg < τ = 2π."
            return abs(pos), atan2(pos.imag, pos.real) % tau
        def fill(self, pos):
            """Fill the next available number into grid[pos], increment, and
            update border = {free cells that are neighbor to a filled cell}."""
            self.grid[pos] = len(self.terms); self.border.remove(pos)
            self.border |= {pos+N for N in self.neighbors if pos+N not in self.grid}
            self.terms += [int(4*y**2-y-x if (y:=pos.imag)>=abs(x:=pos.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 second(self,pos):
            """Find the second cell adjacent to 'pos' so that the domino is oriented
            according the rules (closest to origin but no domino side-by-side)."""
            return min((pos+dir for dir in(1, 1j, -1, -1j) if pos+dir not in self.grid
                and all(self.grid.get(p+dir, -1) != self.grid.get(p, -1) ^ 1
                        for p in (pos+1j*dir, pos-1j*dir) ) ), key = self.distance)
    from math import atan2, tau
    print(A383190()[:50])
    print(A383190()) # displays the grid filled so far
Showing 1-1 of 1 results.