OFFSET
1,2
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
EXAMPLE
The start of the sequence as triangle array read by rows:
1;
2,1;
2,3,1;
2,4,3,1;
2,4,5,3,1;
2,4,6,5,3,1;
2,4,6,7,5,3,1;
2,4,6,8,7,5,3,1;
. . .
Row number r contains permutation numbers from 1 to r: 2,4,6,...2*floor(r/2),2*floor(r/2)-1,2*floor(r/2)-3,...3,1.
PROG
(Python)
t=int((math.sqrt(8*n-7)-1)/2)
i=n-t*(t+1)/2
v=int((2*n+1-t*(t+1))/(t+3))
result=2*i-v*(4*i-2*t-3)
CROSSREFS
KEYWORD
nonn
AUTHOR
Boris Putievskiy, Jan 28 2013
STATUS
approved