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) by diagonals. The order of the list
if n is odd - T(n-1,2),T(n-3,4),...,T(2,n-1),T(1,n),T(3,n-2),...T(n,1).
if n is even - T(n-1,2),T(n-3,4),...,T(3,n-2),T(1,n),T(2,n-1),...T(n,1).
Table T(n,k) contains:
Column number 1 A000217,
column number 2 A000124,
column number 3 A000096,
column number 4 A152948,
column number 5 A034856,
column number 6 A152950,
column number 7 A055998.
Row numder 1 A000982,
row number 2 A097063.
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) read by antidiagonals
T(n,k) = n*n/2+4*(floor((k-1)/2)+1)*n+ceiling((k-1)^2/2), n,k > 0.
As linear sequence
a(n) = (m1+m2-1)*(m1+m2-2)/2+m1, where
m1 = int((i+j)/2)+int(i/2)*(-1)^(i+t+1),
m2 = int((i+j+1)/2)+int(i/2)*(-1)^(i+t),
t = int((math.sqrt(8*n-7) - 1)/ 2),
i = n-t*(t+1)/2,
j = (t*t+3*t+4)/2-n.
EXAMPLE
The start of the sequence as table:
1....2...5...8..13..18...25...32...41...
3....4...9..12..19..24...33...40...51...
6....7..14..17..26..31...42...49...62...
10..11..20..23..34..39...52...59...74...
15..16..27..30..43..48...63...70...87...
21..22..35..38..53..58...75...82..101...
28..29..44..47..64..69...88...95..116...
36..37..54..57..76..81..102..109..132...
45..46..65..68..89..94..117..124..149...
. . .
The start of the sequence as triangle array read by rows:
1;
2,3;
5,4,6;
8,9,7,10;
13,12,14,11,15;
18,19,17,20,16,21;
25,24,26,23,27,22,28;
32,33,31,34,30,35,29,36;
41,40,42,39,43,38,44,37,45;
. . .
Row number r contains permutation from r numbers:
if r is odd ceiling(r^2/2), ceiling(r^2/2)+1, ceiling(r^2/2)-1, ceiling(r^2/2)+2, ceiling(r^2/2)-2,...r*(r+1)/2;
if r is even ceiling(r^2/2), ceiling(r^2/2)-1, ceiling(r^2/2)+1, ceiling(r^2/2)-2, ceiling(r^2/2)+2,...r*(r+1)/2;
MATHEMATICA
max = 10; row[n_] := Table[Ceiling[(n + k - 1)^2/2] + If[OddQ[k], 1, -1]*Floor[n/2], {k, 1, max}]; t = Table[row[n], {n, 1, max}]; Table[t[[n - k + 1, k]], {n, 1, max}, {k, n, 1, -1}] // Flatten (* Jean-François Alcover, Jan 17 2013 *)
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
m1=int((i+j)/2)+int(i/2)*(-1)**(i+t+1)
m2=int((i+j+1)/2)+int(i/2)*(-1)**(i+t)
m=(m1+m2-1)*(m1+m2-2)/2+m1
CROSSREFS
KEYWORD
nonn,tabl
AUTHOR
Boris Putievskiy, Jan 16 2013
STATUS
approved