A213922 Natural numbers placed in table T(n,k) layer by layer. The order of placement: T(n,n), T(n-1,n), T(n,n-1), ... T(1,n), T(n,1). Table T(n,k) read by antidiagonals.
1, 3, 4, 8, 2, 9, 15, 6, 7, 16, 24, 13, 5, 14, 25, 35, 22, 11, 12, 23, 36, 48, 33, 20, 10, 21, 34, 49, 63, 46, 31, 18, 19, 32, 47, 64, 80, 61, 44, 29, 17, 30, 45, 62, 81, 99, 78, 59, 42, 27, 28, 43, 60, 79, 100, 120, 97, 76, 57, 40, 26, 41, 58, 77, 98, 121
Offset: 1
Examples
The start of the sequence as a table: 1, 3, 8, 15, 24, 35, ... 4, 2, 6, 13, 22, 33, ... 9, 7, 5, 11, 20, 31, ... 16, 14, 12, 10, 18, 29, ... 25, 23, 21, 19, 17, 27, ... 36, 34, 32, 30, 28, 26, ... ... The start of the sequence as triangular array read by rows: 1; 3, 4; 8, 2, 9; 15, 6, 7, 16; 24, 13, 5, 14, 25; 35, 22, 11, 12, 23, 36; ...
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 W. Weisstein, MathWorld: Pairing functions
- Index entries for sequences that are permutations of the natural numbers
Crossrefs
Programs
-
Mathematica
f[n_, k_] := n^2 - 2*k + 2 /; n >= k; f[n_, k_] := k^2 - 2*n + 1 /; n < k; TableForm[Table[f[n, k], {n, 1, 5}, {k, 1, 10}]]; Table[f[n - k + 1, k], {n, 5}, {k, n, 1, -1}] // Flatten (* G. C. Greubel, Aug 19 2017 *)
-
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*i-2*j+2 else: result=j*j-2*i+1
Formula
As a table,
T(n,k) = n*n - 2*k + 2, if n >= k;
T(n,k) = k*k - 2*n + 1, if n < k.
As a linear sequence,
a(n) = i*i - 2*j + 2, if i >= j;
a(n) = j*j - 2*i + 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).
Comments