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.

A327759 a(1) = 1; a(2) = 2; a(n) = n - max{k

Original entry on oeis.org

1, 2, 2, 3, 1, 2, 1, 4, 5, 1, 2, 4, 1, 5, 1, 2, 5, 1, 2, 8, 4, 5, 3, 4, 3, 6, 1, 8, 3, 2, 5, 4, 7, 6, 2, 3, 9, 1, 2, 12, 4, 5, 3, 4, 8, 9, 7, 8, 3, 10, 1, 12, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 2, 3, 13, 1, 2, 16, 4, 5, 3, 4, 8, 9, 7, 8, 12, 13, 11, 12, 3
Offset: 1

Views

Author

Ali Sada, Sep 24 2019

Keywords

Comments

From M. F. Hasler, Sep 29 2019: (Start)
The sequence may be seen as a table with rows of length |2n-1|, n = 0, 1, ...
Then from n = 5, a(18) = 1 on, the rows are of the form
row(n) = (1, 2, 2n-2, ((4k, 4k+1, 4k-1, 4k), k=1..(n-3)/2), 3, 2n-4) for odd n,
row(n) = (1, 2n-4, ((2k+1, 2k), k=1..n-3), 2, 3, 2n-3) for even n.
All rows n >= 5 start with a((n-1)^2 + 2) = 1, and there are no other '1's beyond a(15). (End)

Examples

			a(9) is odd. The largest term up to that point is 5. The largest index of 5 is 9. a(10) = 10 - 9 = 1.
a(16) is even. The second largest term up to that point is 4. The largest index of 4 is 12. a(17) = 17 - 12 = 5.
From _M. F. Hasler_, Sep 29 2019: (Start)
Written as a table with rows of length |2n-1|, n = 0, 1, ...:
   1,  /* row n=0 */
   2,  /* row n=1; from here on, length = 2n-1 */
   2, 3, 1,  /* row n=2 */
   2, 1, 4, 5, 1,  /* row n=3 */
   2, 4, 1, 5, 1, 2, 5,  /* n=4 */
   1, 2, 8, 4, 5, 3, 4, 3, 6,  /* n=5. Here starts the regular pattern. */
   1, 8, 3, 2, 5, 4, 7, 6, 2, 3, 9,  /* n=6 */
   1, 2, 12, 4, 5, 3, 4, 8, 9, 7, 8, 3, 10,  /* n=7 */
   1, 12, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 2, 3, 13,  /* n=8 */
   1, 2, 16, 4, 5, 3, 4, 8, 9, 7, 8, 12, 13, 11, 12, 3, 14,  /* n=9 */
   1, 16, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 2, 3, 17,  /* n=10 */
   ...
(End)
		

Crossrefs

Cf. A059100 (indices of '1's, starting with 18), A141044 (col.1, starting at row 3).

Programs

  • Mathematica
    s={1, 2}; sm = 2; sm2 = 1; Do[a = Length[s] + 1 - If[OddQ[s[[-1]]], Position[s, ?(# == sm &)], Position[s, ?(# == sm2 &)]][[-1, 1]]; AppendTo[s, a]; If[a > sm, sm2 = sm; sm = a,If[a < sm && a > sm2, sm2 = a]], {100}]; s (* Amiram Eldar, Sep 28 2019 *)
  • PARI
    A327759_upto(N=99, idx=[0,0], L, S, a)=vector(N,n,a=n-if(n>2,idx[2-a%2]); LM. F. Hasler, Sep 29 2019
    
  • PARI
    A327759(n)={my(r=sqrtint(abs(n-2))+1,c=n-(r-1)^2-1); if(n<17, digits(1223121451241512)[n], c==1, 1, c==2*r-2, 3,c==2*r-1, 2*r-3-r%2, r%2, if(c==3, 2*r-2, c>2, c\4*4+[0,1,-1,0][c-c\4*4+1], 2), c==2, 2*r-4, c<2*r-3, c\/2*2+(c%2)-2,2)} \\ M. F. Hasler, Sep 30 2019
    
  • Python
    def A327759list(nmax):
        A = [1,2]
        for n in range(3,nmax+1):
            if A[-1]%2 == 0:
                A2 = list(set(A))
                A2.sort()
                m = A2[-2]
            else: m = max(A)
            i = len(A) - 1
            while A[i] != m: i -= 1
            A.append(n-i-1)
        print(A) # John Tyler Rascoe, Jan 13 2023

Formula

a(n) = 1 iff n is in {1, 5, 7, 10, 13, 15} union A059100 \ { 2, 3, 6, 11 }.