login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A081344
Natural numbers in square maze arrangement, read by antidiagonals.
18
1, 2, 4, 9, 3, 5, 10, 8, 6, 16, 25, 11, 7, 15, 17, 26, 24, 12, 14, 18, 36, 49, 27, 23, 13, 19, 35, 37, 50, 48, 28, 22, 20, 34, 38, 64, 81, 51, 47, 29, 21, 33, 39, 63, 65, 82, 80, 52, 46, 30, 32, 40, 62, 66, 100, 121, 83, 79, 53, 45, 31, 41, 61, 67, 99, 101, 122, 120, 84, 78, 54
OFFSET
1,2
COMMENTS
Arrange the natural numbers by taking clockwise and counterclockwise turns. Begin (LL) and then repeat (RRR)(LLL).
a(n) is a pairing function: a function that reversibly maps Z^{+} x Z^{+} onto Z^{+}, where Z^{+} is the set of integer positive numbers. - Boris Putievskiy, Dec 16 2012
For generalizations see A219159, A213928. - Boris Putievskiy, Mar 10 2013
FORMULA
From Boris Putievskiy, Dec 19 2012: (Start)
a(n) = (i-1)^2 + i + (i-j)*(-1)^(i-1) if i >= j,
a(n) = (j-1)^2 + j - (j-i)*(-1)^(j-1) if i < j,
where
i = n - t*(t+1)/2,
j = (t*t + 3*t + 4)/2-n,
t = floor((-1 + sqrt(8*n-7))/2). (End)
EXAMPLE
The start of the sequence as table T(i,j), i,j > 0:
1 .. 4 .. 5 .. 16...
2 .. 3 .. 6 .. 15...
9 .. 8 .. 7 .. 14...
10..11 ..12 .. 13...
. . .
Enumeration by boustrophedonic ("ox-plowing") method: If i >= j: T(i,i)=(i-1)^2+i + (i-j)*(-1)^(i-1), if i < j: T(i,j)=(j-1)^2+j - (j-i)*(-1)^(j-1). - Boris Putievskiy, Dec 19 2012
MATHEMATICA
T[n_, k_] := T[n, k] = Which[OddQ[n] && k==1, n^2, EvenQ[k] && n==1, k^2, EvenQ[n] && k==1, T[n-1, 1]+1, OddQ[k] && n==1, T[1, k-1]+1, k <= n, T[n, k-1]+1 - 2 Mod[n, 2], True, T[n-1, k]-1 + 2 Mod[k, 2]]; Table[T[n-k+1, k], {n, 1, 12}, {k, 1, n}] // Flatten (* Jean-François Alcover, Feb 20 2019 *)
PROG
(Python)
t=int((math.sqrt(8*n-7) - 1)/ 2)
i=n-t*(t+1)/2
j=(t*t+3*t+4)/2-n
if j >= i:
m=(j-1)**2 + j + (j-i)*(-1)**(j-1)
else:
m=(i-1)**2 + i - (i-j)*(-1)**(i-1)
# Boris Putievskiy, Dec 19 2012
(Python)
from math import isqrt
def A081344(n):
t = (k:=isqrt(m:=n<<1))+((m<<2)>(k<<2)*(k+1)+1)-1
i, j = n-(t*(t+1)>>1), (t*(t+3)>>1)+2-n
r = max(i, j)
return (r-1)**2+r+(j-i if r&1 else i-j) # Chai Wah Wu, Nov 04 2024
CROSSREFS
Cf. A219159, A213928. The main diagonal is A002061. The following appear within interlaced sequences: A016754, A001844, A053755, A004120. The first row is A081345. The first column is A081346. The inverse permutation A194280, the first inverse function (numbers of rows) A220603, the second inverse function (numbers of columns) A220604.
Sequence in context: A155523 A019912 A354903 * A227272 A021405 A201946
KEYWORD
nonn,tabl
AUTHOR
Paul Barry, Mar 19 2003
STATUS
approved