OFFSET
1,2
COMMENTS
Permutation of the natural numbers.
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.
Enumeration table T(n,k). Let m be natural number. The order of the list:
T(1,1)=1;
T(1,2), T(1,3), T(2,2), T(2,1), T(3,1);
. . .
T(1,2*m), T(1,2*m+1), T(2,2*m), T(2,2*m-1), T(3,2*m-2), ... T(2*m-1,2), T(2*m-1,3), T(2*m,2), T(2*m,1), T(2*m+1,1);
. . .
Movement along two adjacent antidiagonals - step to the east, step to the southwest, step to the west, step to the southwest and so on. The length of each step is 1.
LINKS
Boris Putievskiy, Rows n = 1..140 of triangle, flattened
Boris Putievskiy, Transformations [of] Integer Sequences And Pairing Functions arXiv:1212.2732 [math.CO]
Eric W. Weisstein, MathWorld: Pairing functions
FORMULA
As table
T(n,k)=((n+k)^2-4*k+3-(-1)^k-(n+k-2)*(-1)^(n+k))/2-1, if k=1 and (n mod 2)=1;
T(n,k)=((n+k)^2-4*k+3-(-1)^k-(n+k-2)*(-1)^(n+k))/2, else.
As linear sequence
a(n)=((t+2)^2-4*j+3-(-1)^j-(t)*(-1)^t)/2 -1, if j=1 and (i mod 2)=1;
a(n)=((t+2)^2-4*j+3-(-1)^j-(t)*(-1)^t)/2, else; where i=n-t*(t+1)/2, j=(t*t+3*t+4)/2-n, t=floor((-1+sqrt(8*n-7))/2).
EXAMPLE
The start of the sequence as table:
1....2...3...7...8..16..17...
5....4..10...9..19..18..32...
6...11..12..20..21..33..34...
14..13..23..22..36..35..53...
15..24..25..37..38..54..55...
27..26..40..39..57..56..78...
28..41..42..58..59..79..80...
. . .
The start of the sequence as triangular array read by rows:
1;
2,5;
3,4,6;
7,10,11,14;
8,9,12,13,15;
16,19,20,23,24,27;
17,18,21,22,25,26,28;
. . .
The start of the sequence as array read by rows, the length of row number r is 4*r-3.
First 2*r-2 numbers are from the row number 2*r-2 of triangle array, located above.
Last 2*r-1 numbers are from the row number 2*r-1 of triangle array, located above.
1;
2,5,3,4,6;
7,10,11,14,8,9,12,13,15;
16,19,20,23,24,27,17,18,21,22,25,26,28;
. . .
Row number r contains permutation of the 4*r-3 numbers from 2*r*r-5*r+4 to 2*r*r-r:
2*r*r-5*r+4, 2*r*r-5*r+7, ... 2*r*r-r-2, 2*r*r-r.
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
result=((t+2)**2-4*j+3-(-1)**j-(t)*(-1)**t)/2
if j==1 and (i%2)==1:
result=result-1
CROSSREFS
KEYWORD
nonn,tabl
AUTHOR
Boris Putievskiy, Mar 14 2013
STATUS
approved