OFFSET
1,2
COMMENTS
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.
Layer is pair of sides of square from T(1,n) to T(n,n) and from T(n,n) to T(n,1).
Enumeration table T(n,k) layer by layer. The order of the list:
T(1,1)=1;
T(2,2), T(1,2), T(2,1);
. . .
T(n,n), T(1,n), T(n,1), T(2,n), T(n,2),...T(n-1,n), T(n,n-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], 2012.
Eric Weisstein's World of Mathematics, Pairing functions
FORMULA
As table
T(n,k) = (n-1)^2+1, if n=k;
T(n,k) = (n-1)^2+2*k+1, if n>k;
T(n,k) = (k-1)^2+2*n, if n<k.
As linear sequence
a(n) = (i-1)^2+1, if i=j;
a(n) = (i-1)^2+2*j+1, if i>j;
a(n) = (j-1)^2+2*i, 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).
EXAMPLE
The start of the sequence as table:
1....3...6..11..18..27...
4....2...8..13..20..29...
7....9...5..15..22..31...
12..14..16..10..24..33...
19..21..23..25..17..35...
28..30..32..34..36..26...
. . .
The start of the sequence as triangle array read by rows:
1;
3,4;
6,2,7;
11,8,9,12;
18,13,5,14,19;
27,20,15,16,21,28;
. . .
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 i == j:
result=(i-1)**2+1
if i > j:
result=(i-1)**2+2*j+1
if i < j:
result=(j-1)**2+2*i
CROSSREFS
KEYWORD
nonn,tabl
AUTHOR
Boris Putievskiy, Mar 11 2013
STATUS
approved