cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

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.

Original entry on oeis.org

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

Views

Author

Boris Putievskiy, Feb 19 2013

Keywords

Comments

Permutation of the natural numbers.
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.
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.
For m = 1 the result is A081344. This sequence is result for m = 2.

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;
   ...
		

Crossrefs

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