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.
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
Keywords
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
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
Comments