A218890 T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k)/2))*n + (1 +(-1)^floor((n + k)/2))*k)/2; n , k > 0, read by antidiagonals.
1, 2, 3, 6, 5, 4, 10, 9, 8, 7, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 28, 27, 26, 25, 24, 23, 22, 36, 35, 34, 33, 32, 31, 30, 29, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 78
Offset: 1
Examples
The start of the sequence as table. The direction of the placement denotes by ">" and "v". v...v v...v ..1...2...6..10..11..16..28..36... ..3...5...9..12..17..27..35..38... > 4...8..13..18..26..34..39..48... > 7..14..19..25..33..40..49..63... .15..20..24..32..41..50..62..74... .21..23..31..42..51..61..73..84... >22..30..43..52..60..72..85..98... >29..44..53..59..71..86..99.113... . . . The start of the sequence as triangle array read by rows: 1; 2, 3; 6, 5, 4; 10, 9, 8, 7; 11, 12, 13, 14, 15; 16, 17, 18, 19, 20, 21; 28, 27, 26, 25, 24, 23, 22; 36, 35, 34, 33, 32, 31, 30, 29; ... Row r consists of r consecutive numbers from r*r/2 - r/2 + 1 to r*r/2 + r. If r congruent to 1 or 2 mod 4 rows are increasing. If r congruent to 0 or 3 mod 4 rows are decreasing.
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
Programs
-
Maple
T:=(n,k)->((n+k-1)*(n+k-2)-(-1+(-1)^floor((n+k)/2))*n+(1+(-1)^floor((n+k)/2))*k)/2: seq(seq(T(k,n-k),k=1..n-1),n=1..13); # Muniru A Asiru, Dec 13 2018
-
Mathematica
T[n_, k_] := ((n+k-1)(n+k-2) - (-1 + (-1)^Floor[(n+k)/2])n + (1 + (-1)^Floor[(n+k)/2]) k)/2; Table[T[n-k+1, k], {n, 1, 12}, {k, n, 1, -1}] // Flatten (* Jean-François Alcover, Dec 06 2018 *)
-
Maxima
T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k)/2))*n + (1 +(-1)^floor((n + k)/2))*k)/2$ create_list(T(k, n - k), n, 1, 12, k, 1, n - 1); /* Franck Maminirina Ramaharo, Dec 13 2018 */
-
Python
t=int((math.sqrt(8*n-7) - 1)/ 2) i=n-t*(t+1)/2 j=(t*t+3*t+4)/2-n z=i+j result=((z-1)*(z-2)-(-1+(-1)**int(z/2))*i+(1+(-1)**int(z/2))*j)/2
Formula
For the general case.
As a table
T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k + m - 2)/m))*n + (1 +(-1)^floor((n + k + m - 2)/m))*k)/2.
As linear sequence
a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^floor((z + m - 2)/m))*i + (1 + (-1)^floor((z + m - 2)/m))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.
If we change the order of placement - m antidiagonals upwards, m antidiagonals downwards and so on.
As a table
T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^(floor((n + k + m - 2)/m) + 1))*n + (1 + (-1)^(floor((n + k + m - 2)/m) + 1))*k)/2.
As linear sequence
a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^(floor((z + m - 2)/m) + 1))*i + (1 + (-1)^(floor((z + m - 2)/m) + 1))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.
For this sequence.
As a table
T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 +(-1)^floor((n + k)/2))*n + (1 + (-1)^floor((n + k)/2))*k)/2.
As linear sequence
a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^floor(z/2))*i + (1 + (-1)^floor(z/2))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.
Comments