login
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.
3

%I #53 Nov 29 2023 06:58:01

%S 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,

%T 27,49,50,38,34,22,20,28,48,64,81,51,39,33,21,29,47,63,65,100,80,52,

%U 40,32,30,46,62,66,82,101,99,79,53,41,31,45,61,67,83,121

%N 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.

%C Permutation of the natural numbers.

%C 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.

%C In general, let m be natural number. Layer is pair of sides of square table T(n,k) from T(1,n) to T(n,n) and from T(n,n) to T(n,1). Natural numbers placed in the table T(n,k) layer by layer. The order of placement - at the beginning m layers counterclockwise, next m layers clockwise and so on. T(n,k) read by antidiagonals.

%C For m = 1 the result is A081344. This sequence is result for m = 2.

%H Boris Putievskiy, <a href="/A219159/b219159.txt">Rows n = 1..140 of triangle, flattened</a>

%H Boris Putievskiy, <a href="http://arxiv.org/abs/1212.2732">Transformations [of] Integer Sequences And Pairing Functions</a> arXiv:1212.2732 [math.CO], 2012.

%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PairingFunction.html">Pairing functions</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F For general case.

%F As table

%F 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.

%F As linear sequence

%F 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).

%F For this sequence.

%F As table

%F 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.

%F As linear sequence

%F 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).

%e The start of the sequence as table.

%e The direction of the placement denotes by ">" and "v".

%e v..v v...v

%e .>1...4...5..10..25..36..37..50...

%e .>2...3...6..11..24..35..38..51...

%e ..9...8...7..12..23..34..39..52...

%e .16..15..14..13..22..33..40..53...

%e >17..18..19..20..21..32..41..54...

%e >26..27..28..29..30..31..42..55...

%e .49..48..47..46..45..44..43..56...

%e .64..63..62..61..60..59..58..57...

%e . . .

%e The start of the sequence as triangle array read by rows:

%e 1;

%e 4, 2;

%e 5, 3, 9;

%e 10, 6, 8, 16;

%e 25, 11, 7, 15, 17;

%e 36, 24, 12, 14, 18, 26;

%e 37, 35, 23, 13, 19, 27, 49;

%e 50, 38, 34, 22, 20, 28, 48, 64;

%e ...

%t 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];

%t Table[T[n-k+1, k], {n, 1, 11}, {k, n, 1, -1}] // Flatten (* _Jean-François Alcover_, Dec 11 2018 *)

%o (Python)

%o t=int((math.sqrt(8*n-7) - 1)/ 2)

%o i=n-t*(t+1)/2

%o j=(t*t+3*t+4)/2-n

%o if j >= i:

%o result=((1+(-1)**int((j-1)/2))*(j**2-i+1)-(-1+(-1)**int((j-1)/2))*((j-1)**2 +i))/2

%o else:

%o result=((1+(-1)**(int((i-1)/2)+1))*(i**2-j+1)-(-1+(-1)**(int((i-1)/2)+1))*((i-1)**2 +j))/2

%o (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$

%o create_list(T(k, n - k), n, 1, 12, k, 1, n - 1); /* _Franck Maminirina Ramaharo_, Dec 11 2018 */

%Y Cf. A081344, A194280.

%K nonn,tabl

%O 1,2

%A _Boris Putievskiy_, Feb 19 2013