A327759
a(1) = 1; a(2) = 2; a(n) = n - max{k
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
Keywords
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)
Links
- John Tyler Rascoe, Table of n, a(n) for n = 1..10000
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 }.
Comments