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.

A005185 Hofstadter Q-sequence: a(1) = a(2) = 1; a(n) = a(n-a(n-1)) + a(n-a(n-2)) for n > 2.

Original entry on oeis.org

1, 1, 2, 3, 3, 4, 5, 5, 6, 6, 6, 8, 8, 8, 10, 9, 10, 11, 11, 12, 12, 12, 12, 16, 14, 14, 16, 16, 16, 16, 20, 17, 17, 20, 21, 19, 20, 22, 21, 22, 23, 23, 24, 24, 24, 24, 24, 32, 24, 25, 30, 28, 26, 30, 30, 28, 32, 30, 32, 32, 32, 32, 40, 33, 31, 38, 35, 33, 39, 40, 37, 38, 40, 39
Offset: 1

Views

Author

Simon Plouffe and N. J. A. Sloane, May 20 1991

Keywords

Comments

Rate of growth is not known. In fact it is not even known if this sequence is defined for all positive n.
Roman Pearce, Aug 29 2014, has computed that a(n) exists for n <= 10^10. - N. J. A. Sloane
a(n) exists for n <= 3*10^10. - M. Eric Carr, Jul 02 2023

Examples

			a(18) = 11 because a(17) is 10 and a(16) is 9, so we take a(18 - 10) + a(18 - 9) = a(8) + a(9) = 5 + 6 = 11.
		

References

  • B. W. Conolly, "Meta-Fibonacci sequences," in S. Vajda, editor, Fibonacci and Lucas Numbers and the Golden Section. Halstead Press, NY, 1989, pp. 127-138.
  • R. K. Guy, Unsolved Problems in Number Theory, Sect. E31.
  • D. R. Hofstadter, Goedel, Escher, Bach: an Eternal Golden Braid, Random House, 1980, p. 138.
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
  • S. Vajda, Fibonacci and Lucas Numbers and the Golden Section, Wiley, 1989, see p. 129.
  • S. Wolfram, A New Kind of Science, Wolfram Media, 2002; p. 129.

Crossrefs

Cf. A081827 (first differences).
Cf. A226244, A226245 (record values and where they occur).
See A244477 for a different start.

Programs

  • C
    #include 
    #define LIM 20
    int Qa[LIM];
    int Q(int n){if (n==1 || n==2){return 1;} else{return Qa[n-Qa[n-1]]+Qa[n-Qa[n-2]];}}
    int main(){int i;printf("n\tQ\n");for(i=1; iGonzalo Ciruelos, Aug 01 2013
    
  • Haskell
    a005185 n = a005185_list !! (n-1)
    a005185_list = 1 : 1 : zipWith (+)
       (map a005185 $ zipWith (-) [3..] a005185_list)
       (map a005185 $ zipWith (-) [3..] $ tail a005185_list)
    -- Reinhard Zumkeller, Jun 02 2013, Sep 15 2011
    
  • Magma
    I:=[1,1]; [n le 2 select I[n] else Self(n-Self(n-1))+Self(n-Self(n-2)): n in [1..90]]; // Vincenzo Librandi, Aug 08 2014
    
  • Maple
    A005185 := proc(n) option remember;
        if n<=2 then 1
        elif n > procname(n-1) and n > procname(n-2) then
            RETURN(procname(n-procname(n-1))+procname(n-procname(n-2)));
        else
            ERROR(" died at n= ", n);
        fi; end proc;
    # More generally, the following defines the Hofstadter-Huber sequence Q(r,s) - N. J. A. Sloane, Apr 15 2014
    r:=1; s:=2;
    a:=proc(n) option remember; global r,s;
    if n <= s then  1
    else
        if (a(n-r) <= n) and (a(n-s) <= n) then
        a(n-a(n-r))+a(n-a(n-s));
        else lprint("died with n =",n); return (-1);
        fi; fi; end;
    [seq(a(n), n=1..100)];
  • Mathematica
    a[1]=a[2]=1; a[n_]:= a[n]= a[n -a[n-1]] + a[n -a[n-2]]; Table[ a[n], {n,70}]
  • MuPAD
    q:=proc(n) option remember; begin if n<=2 then 1 else q(n-q(n-1))+q(n-q(n-2)) end_if; end_proc: q(i)$i=1..100; // Zerinvary Lajos, Apr 03 2007
    
  • PARI
    {a(n)= local(A); if(n<1, 0, A=vector(n,k,1); for(k=3, n, A[k]= A[k-A[k-1]]+ A[k-A[k-2]]); A[n])} /* Michael Somos, Jul 16 2007 */
    
  • Python
    from functools import lru_cache
    @lru_cache(maxsize=None)
    def a(n):
        if n < 3: return 1
        return a(n - a(n-1)) + a(n - a(n-2))
    print([a(n) for n in range(1, 75)]) # Michael S. Branicky, Jul 26 2021
  • Sage
    @CachedFunction
    def a(n):
        if (n<3): return 1
        else: return a(n -a(n-1)) + a(n -a(n-2))
    [a(n) for n in (1..70)] # G. C. Greubel, Feb 13 2020
    
  • Scheme
    (define q (lambda (n) (cond ( (eqv? n 0) 1) ( (eqv? n 1) 1) ( #t (+ (q (- n (q (- n 1)))) (q (- n (q (- n 2)))))))))
    
  • Scheme
    ;; An implementation of memoization-macro definec can be found for example in: http://oeis.org/wiki/Memoization
    (definec (A005185 n) (if (<= n 2) 1 (+ (A005185 (- n (A005185 (- n 1)))) (A005185 (- n (A005185 (- n 2)))))))
    ;; Antti Karttunen, Mar 22 2017
    

A046699 a(1) = a(2) = 1, a(n) = a(n - a(n-1)) + a(n-1 - a(n-2)) if n > 2.

Original entry on oeis.org

1, 1, 2, 2, 3, 4, 4, 4, 5, 6, 6, 7, 8, 8, 8, 8, 9, 10, 10, 11, 12, 12, 12, 13, 14, 14, 15, 16, 16, 16, 16, 16, 17, 18, 18, 19, 20, 20, 20, 21, 22, 22, 23, 24, 24, 24, 24, 25, 26, 26, 27, 28, 28, 28, 29, 30, 30, 31, 32, 32, 32, 32, 32, 32, 33, 34, 34, 35, 36, 36, 36, 37
Offset: 1

Views

Author

Keywords

Comments

Ignoring first term, this is the meta-Fibonacci sequence for s=0. - Frank Ruskey and Chris Deugau (deugaucj(AT)uvic.ca)
Except for the first term, n occurs A001511(n) times. - Franklin T. Adams-Watters, Oct 22 2006

References

  • Sequence was proposed by Reg Allenby.
  • B. W. Conolly, "Meta-Fibonacci sequences," in S. Vajda, editor, Fibonacci and Lucas Numbers and the Golden Section. Halstead Press, NY, 1989, pp. 127-138. See Eq. (2).
  • Michael Doob, The Canadian Mathematical Olympiad & L'Olympiade Mathématique du Canada 1969-1993, Canadian Mathematical Society & Société Mathématique du Canada, Problem 5, 1990, pp. 212-213, 1993.
  • S. Vajda, Fibonacci and Lucas Numbers and the Golden Section, Wiley, 1989, see p. 129.
  • S. Wolfram, A New Kind of Science, Wolfram Media, 2002; p. 129.

Crossrefs

Callaghan et al. (2005)'s sequences T_{0,k}(n) for k=1 through 7 are A000012, A046699, A046702, A240835, A241154, A241155, A240830.

Programs

  • Haskell
    a046699 n = a046699_list !! (n-1)
    a046699_list = 1 : 1 : zipWith (+) zs (tail zs) where
       zs = map a046699 $ zipWith (-) [2..] a046699_list
    -- Reinhard Zumkeller, Jan 02 2012
    
  • Magma
    [ n le 2 select 1 else Self(n - Self(n-1)) + Self(n-1 -Self(n-2)):n in [1..80]]; // Marius A. Burtea, Oct 17 2019
  • Maple
    a := proc(n) option remember; if n <= 1 then return 1 end if; if n <= 2 then return 2 end if; return add(a(n - i + 1 - a(n - i)), i = 1 .. 2) end proc # Frank Ruskey and Chris Deugau (deugaucj(AT)uvic.ca)
    a := proc(n) option remember; if n <= 2 then 1 else a(n - a(n-1)) + a(n-1 - a(n-2)); fi; end; # N. J. A. Sloane, Apr 16 2014
  • Mathematica
    a[n_] := (k = 1; While[ !Divisible[(2*++k)!, 2^(n-1)]]; k); a[1] = a[2] = 1; Table[a[n], {n, 1, 72}] (* Jean-François Alcover, Oct 06 2011, after Benoit Cloitre *)
    CoefficientList[ Series[1 + x/(1 - x)*Product[1 + x^(2^n - 1), {n, 6}], {x, 0, 80}], x] (* or *)
    a[1] = a[2] = 1; a[n_] := a[n] = a[n - a[n - 1]] + a[n - 1 - a[n - 2]]; Array[a, 80] (* Robert G. Wilson v, Sep 08 2014 *)
  • Maxima
    a[1]:1$
    a[2]:1$
    a[n]:=a[n-a[n-1]]+a[n-1-a[n-2]]$
    makelist(a[n],n,2,60); /* Martin Ettl, Oct 29 2012 */
    
  • PARI
    a(n)=if(n<0,1,s=1;while((2*s)!%2^(n-1)>0,s++);s) \\ Benoit Cloitre, Jan 19 2007
    
  • Python
    from sympy import factorial
    def a(n):
        if n<3: return 1
        s=1
        while factorial(2*s)%(2**(n - 1))>0: s+=1
        return s
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 11 2017, after Benoit Cloitre
    

Formula

First differences seem to be A079559. - Vladeta Jovovic, Nov 30 2003. This is correct and not too hard to prove, giving the generating function x + x^2(1+x)(1+x^3)(1+x^7)(1+x^15).../(1-x). - Paul Boddington, Jul 30 2004
G.f.: x + x^2/(1-x) * Product_{n=1}^{infinity} (1 + x^(2^n-1)). - Frank Ruskey and Chris Deugau (deugaucj(AT)uvic.ca)
For n>=1, a(n)=w(n-1) where w(n) is the least k such that 2^n divides (2k)!. - Benoit Cloitre, Jan 19 2007
Conjecture: a(n+1) = a(n) + A215530(a(n) + n) for all n > 0. - Velin Yanev, Oct 17 2019
From Bernard Schott, Dec 03 2021: (Start)
a(n) <= a(n+1) <= a(n) +1.
For n > 1, if a(n) is odd, then a(n+1) = a(n) + 1.
a(2^n+1) = 2^(n-1) + 1 for n > 0.
Results coming from the 5th problem proposed during the 22nd Canadian Mathematical Olympiad in 1990 (link IMO Compendium and Doob reference). (End)

A070867 a(1) = a(2) = 1; a(n) = a(n-1 - a(n-1)) + a(n-1 - a(n-2)).

Original entry on oeis.org

1, 1, 2, 2, 2, 4, 3, 4, 4, 4, 8, 5, 5, 8, 8, 6, 8, 12, 8, 11, 9, 9, 10, 13, 16, 9, 12, 20, 10, 12, 23, 12, 15, 21, 13, 17, 18, 19, 19, 22, 21, 19, 19, 26, 28, 16, 24, 33, 21, 26, 23, 36, 16, 26, 39, 16, 30, 33, 36, 19, 34, 31, 43, 23, 30, 32, 38, 23, 40, 26, 38, 43, 31, 31, 38, 44
Offset: 1

Views

Author

N. J. A. Sloane, May 19 2002

Keywords

References

  • S. Wolfram, A New Kind of Science, Wolfram Media, 2002; p. 129.

Crossrefs

Programs

  • Haskell
    a070867 n = a070867_list !! (n-1)
    a070867_list = 1 : 1 : zipWith (+)
       (map a070867 $ zipWith (-) [2..] a070867_list)
       (map a070867 $ zipWith (-) [2..] $ tail a070867_list)
    -- Reinhard Zumkeller, May 31 2013
    
  • Mathematica
    a[1]=a[2]=1; a[n_]:= a[n]= a[n-1 -a[n-1]] + a[n-1 -a[n-2]]; Table[a[n], {n, 80}]
  • Sage
    @CachedFunction
    def a(n): # A070867
        if (n<3): return 1
        else: return  a(n-1 -a(n-1)) + a(n-1 -a(n-2))
    [a(n) for n in (1..80)] # G. C. Greubel, Mar 28 2022

Formula

a(n) = a(n-1 - a(n-1)) + a(n-1 - a(n-2)), with a(1) = a(2) = 1.

Extensions

More terms from John W. Layman, May 21 2002
Erroneous comma in sequence corrected by Nick Hobson, Feb 17 2007

A063892 a(1) = a(2) = a(3) = 1, a(n) = a(n-a(n-2))+a(n-a(n-3)) for n>3.

Original entry on oeis.org

1, 1, 1, 2, 4, 6, 5, 3, 3, 9, 6, 4, 7, 12, 9, 5, 7, 10, 16, 16, 10, 12, 12, 16, 14, 21, 13, 17, 8, 14, 24, 26, 19, 12, 8, 23, 22, 23, 12, 17, 18, 28, 35, 26, 16, 22, 34, 47, 22, 6, 10, 36, 69, 36
Offset: 1

Views

Author

Henry Bottomley, Aug 29 2001

Keywords

Comments

Undefined for n>54 since a(53)=69>=55.

Examples

			a(7) = a(7-a(5))+a(7-a(4)) = a(7-4)+a(7-2) = a(3)+a(5) = 1+4 = 5.
		

Crossrefs

See A064714 for a variant which does not die.

Programs

  • Maple
    #Q(r,s) with initial values 1,1,1,..., from N. J. A. Sloane, Apr 15 2014
    r:=2; s:=3;
    a:=proc(n) option remember; global r,s;
    if n <= s then 1
    else
        if (a(n-r) <= n) and (a(n-s) <= n) then
        a(n-a(n-r))+a(n-a(n-s));
        else lprint("died with n =",n); return (-1);
        fi;
    fi; end;
    [seq(a(n),n=1..54)];

A284511 a(1) = 1, a(2) = 2, a(3) = 2; a(n) = a(a(n-1)-1) + a(n-a(n-2)) for n > 3.

Original entry on oeis.org

1, 2, 2, 3, 4, 4, 4, 5, 7, 8, 7, 7, 8, 8, 8, 9, 12, 14, 12, 11, 15, 15, 13, 14, 15, 15, 15, 16, 16, 16, 16, 17, 21, 23, 23, 23, 23, 23, 24, 25, 26, 27, 27, 27, 29, 28, 29, 27, 26, 28, 30, 30, 29, 30, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 38, 44, 43, 41, 40, 40, 40, 41, 46, 50
Offset: 1

Views

Author

Altug Alkan, Mar 28 2017

Keywords

Examples

			a(4) = 3 because a(4) = a(a(3) - 1) + a(4 - a(2)) = a(1) + a(2) = 3.
		

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember;
      procname(procname(n-1)-1)+procname(n-procname(n-2))
    end proc:
    a(1):= 1: a(2):= 2: a(3):= 2:
    map(a, [$1..100]); # Robert Israel, Mar 28 2017
  • Mathematica
    a[1]=1; a[2]=a[3]=2; a[n_] := a[n] = a[a[n-1]-1] + a[n-a[n-2]]; Array[a, 74] (* Giovanni Resta, Mar 28 2017 *)
  • PARI
    a=vector(1000); a[1]=1; a[2]=a[3]=2; for(n=4, #a, a[n]=a[a[n-1]-1]+a[n-a[n-2]]); a
    
  • Sage
    @CachedFunction
    def a(n): # A284511
        if (n<4): return 2 - bool(n==1)
        else: return  a(a(n-1)-1) + a(n-a(n-2))
    [a(n) for n in (1..80)] # G. C. Greubel, Mar 28 2022

Formula

a(n) = a(a(n-1)-1) + a(n-a(n-2)), with a(1) = 1, a(2) = 2, a(3) = 2.

A284520 a(1) = 1, a(2) = a(3) = a(4) = 2; a(n) = a(a(n-1)-1) + a(n-a(n-3)-1) for n > 4.

Original entry on oeis.org

1, 2, 2, 2, 3, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8, 8, 8, 8, 9, 10, 11, 12, 13, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 17, 18, 19, 19, 19, 19, 20, 22, 25, 28, 28, 26, 24, 23, 25, 29, 30, 31, 30, 30, 30, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 35, 35, 35
Offset: 1

Views

Author

Altug Alkan, Mar 28 2017

Keywords

Examples

			a(5) = 3 because a(5) = a(a(4)-1) + a(5-a(2)-1) = a(1) + a(2) = 3.
		

Crossrefs

Programs

  • PARI
    a=vector(1000); a[1]=1; a[2]=a[3]=a[4]=2; for(n=5, #a, a[n]=a[a[n-1]-1]+ a[n-a[n-3]-1]); a
Showing 1-6 of 6 results.