A219159 Natural numbers placed in table T(n,k) layer by layer. The order of placement - at the beginning 2 layers counterclockwise, next 2 layers clockwise and so on. T(n,k) read by antidiagonals.
1, 4, 2, 5, 3, 9, 10, 6, 8, 16, 25, 11, 7, 15, 17, 36, 24, 12, 14, 18, 26, 37, 35, 23, 13, 19, 27, 49, 50, 38, 34, 22, 20, 28, 48, 64, 81, 51, 39, 33, 21, 29, 47, 63, 65, 100, 80, 52, 40, 32, 30, 46, 62, 66, 82, 101, 99, 79, 53, 41, 31, 45, 61, 67, 83, 121
Offset: 1
Examples
The start of the sequence as table. The direction of the placement denotes by ">" and "v". v..v v...v .>1...4...5..10..25..36..37..50... .>2...3...6..11..24..35..38..51... ..9...8...7..12..23..34..39..52... .16..15..14..13..22..33..40..53... >17..18..19..20..21..32..41..54... >26..27..28..29..30..31..42..55... .49..48..47..46..45..44..43..56... .64..63..62..61..60..59..58..57... . . . The start of the sequence as triangle array read by rows: 1; 4, 2; 5, 3, 9; 10, 6, 8, 16; 25, 11, 7, 15, 17; 36, 24, 12, 14, 18, 26; 37, 35, 23, 13, 19, 27, 49; 50, 38, 34, 22, 20, 28, 48, 64; ...
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
- Index entries for sequences that are permutations of the natural numbers
Programs
-
Mathematica
T[n_, k_] := If[k >= n, ((1 + (-1)^Floor[(k-1)/2])(k^2 - n + 1) - (-1 + (-1)^Floor[(k-1)/2])((k-1)^2 + n))/2, ((1 + (-1)^(Floor[(n-1)/2] + 1))(n^2 - k + 1) - (-1 + (-1)^(Floor[(n-1)/2] + 1))((n-1)^2 + k))/2]; Table[T[n-k+1, k], {n, 1, 11}, {k, n, 1, -1}] // Flatten (* Jean-François Alcover, Dec 11 2018 *)
-
Maxima
T(n,k) := if k >= n then ((1 + (-1)^floor((k - 1)/2))*(k^2 - n + 1) - (-1 + (-1)^floor((k - 1)/2))*((k - 1)^2 + n))/2 else ((1 + (-1)^(floor((n - 1)/2) + 1))*(n^2 - k + 1) - (-1 + (-1)^(floor((n - 1)/2) + 1))*((n - 1)^2 +k))/2$ create_list(T(k, n - k), n, 1, 12, k, 1, n - 1); /* Franck Maminirina Ramaharo, Dec 11 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 if j >= i: result=((1+(-1)**int((j-1)/2))*(j**2-i+1)-(-1+(-1)**int((j-1)/2))*((j-1)**2 +i))/2 else: result=((1+(-1)**(int((i-1)/2)+1))*(i**2-j+1)-(-1+(-1)**(int((i-1)/2)+1))*((i-1)**2 +j))/2
Formula
For general case.
As table
T(n,k) = ((1 + (-1)^floor((k - 1)/m))*(k^2 - n + 1) - (-1 + (-1)^floor((k - 1)/m))*((k - 1)^2 + n))/2, if k >= n; T(n,k) = ((1 + (-1)^(floor((n - 1)/m) + 1))*(n^2 - k + 1) - (-1 + (-1)^(floor((n - 1)/m) + 1))*((n - 1)^2 +k))/2, if n > k.
As linear sequence
a(n) = ((1 + (-1)^floor((j - 1)/m))*(j^2 - i + 1) - (-1 + (-1)^floor((j - 1)/m))*((j - 1)^2 + i))/2, if j >= i; a(n) = ((1 + (-1)^(floor((i - 1)/m) + 1))*(i^2 - j + 1) - (-1 + (-1)^(floor((i - 1)/m) + 1))*((i - 1)^2 + j))/2, 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).
For this sequence.
As table
T(n,k) = ((1 + (-1)^floor((k - 1)/2))*(k^2 - n + 1) - (-1 + (-1)^floor((k - 1)/2))*((k - 1)^2 + n))/2, if k >= n; T(n,k) = ((1 + (-1)^(floor((n - 1)/2) + 1))*(n^2 - k + 1) - (-1 + (-1)^(floor((n - 1)/2) + 1))*((n - 1)^2 + k))/2, if n > k.
As linear sequence
a(n) = ((1 + (-1)^floor((j - 1)/2))*(j^2 - i + 1) - (-1 + (-1)^floor((j - 1)/2))*((j - 1)^2 + i))/2, if j >= i; a(n) = ((1 + (-1)^(floor((i - 1)/2) + 1))*(i^2 - j + 1) - (-1 + (-1)^(floor((i - 1)/2) + 1))*((i - 1)^2 + j))/2, 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