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 a(k) = m(n)}, where m(n) is the largest term so far if a(n-1) is odd, the second largest term so far if a(n-1) is even.

This page as a plain text file.
%I A327759 #39 Aug 17 2025 01:05:38
%S A327759 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,
%T A327759 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,
%U A327759 1,2,16,4,5,3,4,8,9,7,8,12,13,11,12,3
%N A327759 a(1) = 1; a(2) = 2; a(n) = n - max{k<n | a(k) = m(n)}, where m(n) is the largest term so far if a(n-1) is odd, the second largest term so far if a(n-1) is even.
%C A327759 From _M. F. Hasler_, Sep 29 2019: (Start)
%C A327759 The sequence may be seen as a table with rows of length |2n-1|, n = 0, 1, ...
%C A327759 Then from n = 5, a(18) = 1 on, the rows are of the form
%C A327759 row(n) = (1, 2, 2n-2, ((4k, 4k+1, 4k-1, 4k), k=1..(n-3)/2), 3, 2n-4) for odd n,
%C A327759 row(n) = (1, 2n-4, ((2k+1, 2k), k=1..n-3), 2, 3, 2n-3) for even n.
%C A327759 All rows n >= 5 start with a((n-1)^2 + 2) = 1, and there are no other '1's beyond a(15). (End)
%H A327759 John Tyler Rascoe, <a href="/A327759/b327759.txt">Table of n, a(n) for n = 1..10000</a>
%F A327759 a(n) = 1 iff n is in {1, 5, 7, 10, 13, 15} union A059100 \ { 2, 3, 6, 11 }.
%e A327759 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.
%e A327759 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.
%e A327759 From _M. F. Hasler_, Sep 29 2019: (Start)
%e A327759 Written as a table with rows of length |2n-1|, n = 0, 1, ...:
%e A327759    1,  /* row n=0 */
%e A327759    2,  /* row n=1; from here on, length = 2n-1 */
%e A327759    2, 3, 1,  /* row n=2 */
%e A327759    2, 1, 4, 5, 1,  /* row n=3 */
%e A327759    2, 4, 1, 5, 1, 2, 5,  /* n=4 */
%e A327759    1, 2, 8, 4, 5, 3, 4, 3, 6,  /* n=5. Here starts the regular pattern. */
%e A327759    1, 8, 3, 2, 5, 4, 7, 6, 2, 3, 9,  /* n=6 */
%e A327759    1, 2, 12, 4, 5, 3, 4, 8, 9, 7, 8, 3, 10,  /* n=7 */
%e A327759    1, 12, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 2, 3, 13,  /* n=8 */
%e A327759    1, 2, 16, 4, 5, 3, 4, 8, 9, 7, 8, 12, 13, 11, 12, 3, 14,  /* n=9 */
%e A327759    1, 16, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14, 2, 3, 17,  /* n=10 */
%e A327759    ...
%e A327759 (End)
%t A327759 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 *)
%o A327759 (VBA/Excel)
%o A327759 Sub A327759()
%o A327759 Cells(1, 1) = 1
%o A327759 Cells(2, 1) = 2
%o A327759 For n = 3 To 1000
%o A327759    max1 = 0
%o A327759    For m = 1 To n - 1
%o A327759       If Cells(m, 1) >= max1 Then
%o A327759           max1 = Cells(m, 1)
%o A327759           m1 = m
%o A327759       End If
%o A327759    Next m
%o A327759    max2 = 0
%o A327759    For m = 1 To n - 1
%o A327759       If Cells(m, 1) <> max1 And Cells(m, 1) >= max2 Then
%o A327759          max2 = Cells(m, 1)
%o A327759          m2 = m
%o A327759       End If
%o A327759    Next m
%o A327759    If Cells(n - 1, 1) Mod 2 = 1 Then
%o A327759       Cells(n, 1) = n - m1
%o A327759    Else
%o A327759       Cells(n, 1) = n - m2
%o A327759    End If
%o A327759 Next n
%o A327759 End Sub
%o A327759 (PARI) A327759_upto(N=99, idx=[0,0], L, S, a)=vector(N,n,a=n-if(n>2,idx[2-a%2]); L<a && [S,idx[2]]=[L,idx[1]]; if(L<=a, L=a; idx[1]=n, S<=a, S=a; idx[2]=n); a) \\ _M. F. Hasler_, Sep 29 2019
%o A327759 (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
%o A327759 (Python)
%o A327759 def A327759list(nmax):
%o A327759     A = [1,2]
%o A327759     for n in range(3,nmax+1):
%o A327759         if A[-1]%2 == 0:
%o A327759             A2 = list(set(A))
%o A327759             A2.sort()
%o A327759             m = A2[-2]
%o A327759         else: m = max(A)
%o A327759         i = len(A) - 1
%o A327759         while A[i] != m: i -= 1
%o A327759         A.append(n-i-1)
%o A327759     print(A) # _John Tyler Rascoe_, Jan 13 2023
%Y A327759 Cf. A059100 (indices of '1's, starting with 18), A141044 (col.1, starting at row 3).
%K A327759 nonn
%O A327759 1,2
%A A327759 _Ali Sada_, Sep 24 2019