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.

Showing 1-6 of 6 results.

A081344 Natural numbers in square maze arrangement, read by antidiagonals.

Original entry on oeis.org

1, 2, 4, 9, 3, 5, 10, 8, 6, 16, 25, 11, 7, 15, 17, 26, 24, 12, 14, 18, 36, 49, 27, 23, 13, 19, 35, 37, 50, 48, 28, 22, 20, 34, 38, 64, 81, 51, 47, 29, 21, 33, 39, 63, 65, 82, 80, 52, 46, 30, 32, 40, 62, 66, 100, 121, 83, 79, 53, 45, 31, 41, 61, 67, 99, 101, 122, 120, 84, 78, 54
Offset: 1

Views

Author

Paul Barry, Mar 19 2003

Keywords

Comments

Arrange the natural numbers by taking clockwise and counterclockwise turns. Begin (LL) and then repeat (RRR)(LLL).
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. - Boris Putievskiy, Dec 16 2012
For generalizations see A219159, A213928. - Boris Putievskiy, Mar 10 2013

Examples

			The start of the sequence as table T(i,j), i,j > 0:
   1   4    5    16 ...
   2   3    6    15 ...
   9   8    7    14 ...
  10  11   12    13 ...
  ....
		

Crossrefs

Cf. A219159, A213928. The main diagonal is A002061. The following appear within interlaced sequences: A016754, A001844, A053755, A004120. The first row is A081345. The first column is A081346. The inverse permutation A194280, the first inverse function (numbers of rows) A220603, the second inverse function (numbers of columns) A220604.

Programs

  • Mathematica
    T[n_, k_] := T[n, k] = Which[OddQ[n] && k==1, n^2, EvenQ[k] && n==1, k^2, EvenQ[n] && k==1, T[n-1, 1]+1, OddQ[k] && n==1, T[1, k-1]+1, k <= n, T[n, k-1]+1 - 2 Mod[n, 2], True, T[n-1, k]-1 + 2 Mod[k, 2]]; Table[T[n-k+1, k], {n, 1, 12}, {k, 1, n}] // Flatten (* Jean-François Alcover, Feb 20 2019 *)
  • 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:
         m=(j-1)**2 + j + (j-i)*(-1)**(j-1)
    else:
         m=(i-1)**2 + i - (i-j)*(-1)**(i-1)
    # Boris Putievskiy, Dec 19 2012
    
  • Python
    from math import isqrt
    def A081344(n):
        t = (k:=isqrt(m:=n<<1))+((m<<2)>(k<<2)*(k+1)+1)-1
        i, j = n-(t*(t+1)>>1), (t*(t+3)>>1)+2-n
        r = max(i,j)
        return (r-1)**2+r+(j-i if r&1 else i-j) # Chai Wah Wu, Nov 04 2024

Formula

From Boris Putievskiy, Dec 19 2012: (Start)
a(n) = (i-1)^2 + i + (i-j)*(-1)^(i-1) if i >= j,
a(n) = (j-1)^2 + j - (j-i)*(-1)^(j-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). (End)
Enumeration by boustrophedonic ("ox-plowing") method: If i >= j: T(i,j)=(i-1)^2+i + (i-j)*(-1)^(i-1), if i < j: T(i,j)=(j-1)^2+j - (j-i)*(-1)^(j-1). - Boris Putievskiy, Dec 19 2012
T(i,j) = m^2 - m + 1 - (i - j)*(-1)^m where m = max(i,j). - Ziad Ahmed, Jun 09 2025

A188568 Enumeration table T(n,k) by descending antidiagonals. The order of the list - if n is odd: T(n,1), T(2,n-1), T(n-2,3), ..., T(n-1,2), T(1,n); if n is even: T(1,n), T(n-1,2), T(3,n-2), ..., T(2,n-1), T(n,1).

Original entry on oeis.org

1, 2, 3, 6, 5, 4, 7, 9, 8, 10, 15, 12, 13, 14, 11, 16, 20, 18, 19, 17, 21, 28, 23, 26, 25, 24, 27, 22, 29, 35, 31, 33, 32, 34, 30, 36, 45, 38, 43, 40, 41, 42, 39, 44, 37, 46, 54, 48, 52, 50, 51, 49, 53, 47, 55
Offset: 1

Views

Author

Boris Putievskiy, Dec 27 2012

Keywords

Comments

Self-inverse 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.
Call a "layer" a pair of sides of square from T(1,n) to T(n,n) and from T(n,n) to T(n,1). This table read layer by layer clockwise is A194280. This table read by boustrophedonic ("ox-plowing") method - layer clockwise, layer counterclockwise and so on - is A064790. - Boris Putievskiy, Mar 14 2013

Examples

			The start of the sequence as table:
   1,  2,  6,  7, 15, 16, 28, ...
   3,  5,  9, 12, 20, 23, 35, ...
   4,  8, 13, 18, 26, 31, 43, ...
  10, 14, 19, 25, 33, 40, 52, ...
  11, 17, 24, 32, 41, 50, 62, ...
  21, 27, 34, 42, 51, 61, 73, ...
  22, 30, 39, 49, 60, 72, 85, ...
  ...
The start of the sequence as triangular array read by rows:
   1;
   2,  3;
   6,  5,  4;
   7,  9,  8, 10;
  15, 12, 13, 14, 11;
  16, 20, 18, 19, 17, 21;
  28, 23, 26, 25, 24, 27, 22;
  ...
Row number k contains permutation of the k numbers:
{ (k^2-k+2)/2, (k^2-k+2)/2 + 1, ..., (k^2+k-2)/2 + 1 }.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Module[{t, i, j},
    t = Floor[(Sqrt[8n-7]-1)/2];
    i = n-t(t+1)/2;
    j = (t^2+3t+4)/2-n;
    ((i+j-1)(i+j-2) + ((-1)^Max[i,j]+1)i - ((-1)^Max[i,j]-1)j)/2];
    Array[a, 55] (* Jean-François Alcover, Jan 26 2019 *)
  • Python
    t=int((math.sqrt(8*n-7) - 1)/ 2)
    i=n-t*(t+1)/2
    j=(t*t+3*t+4)/2-n
    m=((i+j-1)*(i+j-2)+((-1)**max(i,j)+1)*i-((-1)**max(i,j)-1)*j)/2

Formula

a(n) = ((i+j-1)*(i+j-2)+((-1)^max(i,j)+1)*i-((-1)^max(i,j)-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].

A064788 Inverse permutation to A060736.

Original entry on oeis.org

1, 2, 5, 3, 4, 8, 13, 9, 6, 7, 12, 18, 25, 19, 14, 10, 11, 17, 24, 32, 41, 33, 26, 20, 15, 16, 23, 31, 40, 50, 61, 51, 42, 34, 27, 21, 22, 30, 39, 49, 60, 72, 85, 73, 62, 52, 43, 35, 28, 29, 38, 48, 59, 71, 84, 98, 113, 99, 86, 74, 63, 53, 44, 36, 37, 47, 58, 70, 83, 97, 112
Offset: 1

Views

Author

N. J. A. Sloane, Oct 20 2001

Keywords

Crossrefs

Programs

Formula

a(n) = (i+j-1)*(i+j-2)/2+j, where i=min(t; t^2-n+1), j=min(t; n-(t-1)^2), t=floor(sqrt(n-1))+1. - Boris Putievskiy, Dec 24 2012

Extensions

More terms from David Wasserman, Jan 15 2002

A064790 Inverse permutation to A060734.

Original entry on oeis.org

1, 3, 5, 2, 6, 9, 13, 8, 4, 10, 14, 19, 25, 18, 12, 7, 15, 20, 26, 33, 41, 32, 24, 17, 11, 21, 27, 34, 42, 51, 61, 50, 40, 31, 23, 16, 28, 35, 43, 52, 62, 73, 85, 72, 60, 49, 39, 30, 22, 36, 44, 53, 63, 74, 86, 99, 113, 98, 84, 71, 59, 48, 38, 29, 45, 54, 64, 75, 87, 100, 114
Offset: 1

Views

Author

N. J. A. Sloane, Oct 20 2001

Keywords

Comments

From Boris Putievskiy, Mar 14 2013: (Start)
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.
Layer is pair of sides of square from T(1,n) to T(n,n) and from T(n,n) to T(n,1). This sequence is A188568 as table read by boustrophedonic ("ox-plowing") method - layer clockwise, layer counterclockwise and so. The same table A188568 read layer by layer clockwise is A194280. (End)

Examples

			From _Boris Putievskiy_, Mar 14 2013: (Start)
The start of the sequence as table:
  1....2...6...7..15..16..28...
  3....5...9..12..20..23..35...
  4....8..13..18..26..31..43...
  10..14..19..25..33..40..52...
  11..17..24..32..41..50..62...
  21..27..34..42..51..61..73...
  22..30..39..49..60..72..85...
  ...
The start of the sequence as triangular array read by rows:
  1;
  3,5,2;
  6,9,13,8,4;
  10,14,19,25,18,12,7;
  15,20,26,33,41,32,24,17,11;
  21,27,34,42,51,61,50,40,31,23,16;
  28,35,43,52,62,73,85,72,60,49,39,30,22;
  ...
Row number r contains 2*r-1 numbers. (End)
		

Crossrefs

Formula

a(n) = (i+j-1)*(i+j-2)/2+i, where i=min(t; t^2-n+1), j=min(t; n-(t-1)^2), t=floor(sqrt(n-1))+1. - Boris Putievskiy, Dec 24 2012

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

A213928 Natural numbers placed in table T(n,k) layer by layer. The order of placement - at the beginning 2 layers counterclockwise, next 1 layer clockwise and so on. T(n,k) read by antidiagonals.

Original entry on oeis.org

1, 4, 2, 5, 3, 9, 16, 6, 8, 10, 25, 15, 7, 11, 17, 26, 24, 14, 12, 18, 36, 49, 27, 23, 13, 19, 35, 37, 64, 48, 28, 22, 20, 34, 38, 50, 65, 63, 47, 29, 21, 33, 39, 51, 81, 100, 66, 62, 46, 30, 32, 40, 52, 80, 82, 121, 99, 67, 61, 45, 31, 41, 53, 79, 83, 101
Offset: 1

Views

Author

Boris Putievskiy, Mar 06 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 b(z) be a sequence of integer numbers. Layer is pair of sides of square from T(1,n) to T(n,n) and from T(n,n) to T(n,1). Natural numbers placed in table T(n,k) layer by layer. The order of placement - layer is counterclockwise, if b(z) is odd; layer is clockwise if b(z) is even. T(n,k) read by antidiagonals.For A219159 - the order of the placement - at the beginning m layers counterclockwise, next m layers clockwise and so on - b(z)=floor((z-1)/m)+1. For this sequence b(z)=z^2 mod 3.

Examples

			The start of the sequence as table.
The direction of the placement denotes by ">" and  "v".
  ..........v...........v...........v
  >1....4...5..16..25..26..49..64..65...
  >2....3...6..15..24..27..48..63..66...
  .9....8...7..14..23..28..47..62..67...
  >10..11..12..13..22..29..46..61..68...
  >17..18..19..20..21..30..45..60..69...
  .36..35..34..33..32..31..44..59..70...
  >37..38..39..40..41..42..43..58..71...
  >50..51..52..53..54..55..56..57..72...
  .81..80..79..78..77..76..75..74..73...
  . . .
The start of the sequence as triangle array read by rows:
  1;
  4,2;
  5,3,9;
  16,6,8,10;
  25,15,7,11,17;
  26,24,14,12,18,36;
  49,27,23,13,19,35,37;
  64,48,28,22,20,34,38,50;
  65,63,47,29,21,33,39,51,81;
  . . .
		

Crossrefs

Programs

  • 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)**(j**2%3-1))*(j**2-i+1)-(-1+(-1)**(j**2%3-1))*((j-1)**2 +i))/2
    else:
       result=((1+(-1)**(i**2%3))*(i**2-j+1)-(-1+(-1)**(i**2%3))*((i-1)**2 +j))/2

Formula

For general case.
As table
T(n,k) = ((1+(-1)^(b(k)-1))*(k^2-n+1)-(-1+(-1)^(b(k)-1))*((k-1)^2 +n))/2, if k >= n;
T(n,k) = ((1+(-1)^b(n))*(n^2-k+1)-(-1+(-1)^b(n))*((n-1)^2 +k))/2, if n >k.
As linear sequence
a(n) = ((1+(-1)^(b(j)-1))*(j^2-i+1)-(-1+(-1)^(b(j)-1))*((j-1)^2 +i))/2, if j >= i;
a(n) = ((1+(-1)^b(i))*(i^2-j+1)-(-1+(-1)^b(i))*((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 b(z)=z^2 mod 3.
As table
T(n,k) = ((1+(-1)^(k^2 mod 3-1))*(k^2-n+1)-(-1+(-1)^(k^2 mod 3-1))*((k-1)^2 +n))/2, if k >= n;
T(n,k) = ((1+(-1)^(n^2 mod 3))*(n^2-k+1)-(-1+(-1)^(n^2 mod 3))*((n-1)^2 +k))/2, if n >k.
As linear sequence
a(n) = ((1+(-1)^(j^2 mod 3-1))*(j^2-i+1)-(-1+(-1)^(j^2 mod 3-1))*((j-1)^2 +i))/2, if j >= i;
a(n) = ((1+(-1)^(i^2 mod 3))*(i^2-j+1)-(-1+(-1)^(i^2 mod 3))*((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).
Showing 1-6 of 6 results.