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
    

A081828 Numbers n such that 2 successive terms of Hofstadter Q-sequence are the same.

Original entry on oeis.org

1, 4, 7, 9, 10, 12, 13, 18, 20, 21, 22, 25, 27, 28, 29, 32, 41, 43, 44, 45, 46, 54, 59, 60, 61, 82, 87, 90, 91, 92, 93, 94, 102, 111, 133, 154, 157, 163, 177, 182, 186, 187, 188, 189, 190, 273, 334, 342, 350, 360, 367, 378, 379, 380, 381, 382, 418, 431, 441, 464, 483
Offset: 1

Views

Author

Benoit Cloitre, Apr 10 2003

Keywords

Comments

A005185(a(n)+1) = A005185(a(n)); A081827(a(n)) = 0.

Crossrefs

Programs

  • Haskell
    import Data.List (elemIndices)
    a081828 n = a081828_list !! (n-1)
    a081828_list = map (+ 1) $ elemIndices 0 a081827_list
    -- Reinhard Zumkeller, Sep 15 2011

A081829 Numbers n such that the n-th term of Hofstadter Q-sequence is > (n+1)-th term.

Original entry on oeis.org

15, 24, 31, 35, 38, 48, 51, 52, 55, 57, 63, 64, 66, 67, 70, 73, 75, 77, 81, 84, 88, 96, 100, 103, 105, 109, 112, 115, 118, 119, 121, 124, 126, 127, 128, 130, 135, 138, 140, 141, 143, 144, 147, 149, 150, 152, 155, 158, 160, 162, 165, 168, 169, 171, 172, 174, 179
Offset: 1

Views

Author

Benoit Cloitre, Apr 10 2003

Keywords

Comments

A005185(a(n)+1) < A005185(a(n)); A081827(a(n)) < 0.

Crossrefs

Programs

  • Haskell
    import Data.List (findIndices)
    a08182 n = a081829_list !! (n-1)
    a081829_list = map (+ 1) $ findIndices (< 0) a081827_list
    -- Reinhard Zumkeller, Sep 15 2011

Formula

Conjecture : a(n)/n>2 and a(n)/n->2

A081830 Numbers n such that the n-th term of Hofstadter Q-sequence is < (n+1)-th term.

Original entry on oeis.org

2, 3, 5, 6, 8, 11, 14, 16, 17, 19, 23, 26, 30, 33, 34, 36, 37, 39, 40, 42, 47, 49, 50, 53, 56, 58, 62, 65, 68, 69, 71, 72, 74, 76, 78, 79, 80, 83, 85, 86, 89, 95, 97, 98, 99, 101, 104, 106, 107, 108, 110, 113, 114, 116, 117, 120, 122, 123, 125, 129, 131, 132, 134, 136
Offset: 1

Views

Author

Benoit Cloitre, Apr 10 2003

Keywords

Comments

A005185(a(n)+1) > A005185(a(n)); A081827(a(n)) > 0.

Crossrefs

Programs

  • Haskell
    import Data.List (findIndices)
    a081830 n = a081830_list !! (n-1)
    a081830_list = map (+ 1) $ findIndices (> 0) a081827_list
    -- Reinhard Zumkeller, Sep 15 2011

Formula

Conjecture : a(n)/n -> 2. a(n)=2n for n=2, 14, 16, 802, 804, 806, 810, 814, 824, 826, 832, 1116, 1120, 1124, 1126, 1130, 1172, 1178, 1228, 1230, 1254, 1258, 1298...

A194626 Numbers n such that next term of Hofstadter's Q-sequence differs by 1.

Original entry on oeis.org

2, 3, 5, 6, 8, 16, 17, 19, 34, 36, 39, 40, 42, 49, 69, 71, 74, 78, 80, 85, 132, 167, 175, 176, 180, 181, 225, 238, 261, 271, 320, 331, 338, 340, 341, 353, 365, 371, 507, 689, 690, 706, 721, 738, 746, 921, 932, 952, 990, 1012, 1046, 1212, 1351, 1352, 1373
Offset: 1

Views

Author

Reinhard Zumkeller, Sep 15 2011

Keywords

Comments

A005185(a(n)+1) = A005185(a(n)) + 1; A081827(a(n)) = 1.

Crossrefs

Programs

  • Haskell
    import Data.List (elemIndices)
    a194626 n = a194626_list !! (n-1)
    a194626_list = map (+ 1) $ elemIndices 1 a081827_list

A089029 a(n)=n if Hofstadter's Q-sequence increases A005185(n-1)->A005185(n), a(n)=1 otherwise.

Original entry on oeis.org

1, 3, 4, 1, 6, 7, 1, 9, 1, 1, 12, 1, 1, 15, 1, 17, 18, 1, 20, 1, 1, 1, 24, 1, 1, 27, 1, 1, 1, 31, 1, 1, 34, 35, 1, 37, 38, 1, 40, 41, 1, 43, 1, 1, 1, 1, 48, 1, 50, 51, 1, 1, 54, 1, 1, 57, 1, 59, 1, 1, 1, 63, 1, 1, 66, 1, 1, 69, 70, 1, 72, 73, 1, 75, 1, 77, 1, 79, 80, 81, 1, 1, 84, 1, 86, 87, 1, 1
Offset: 2

Views

Author

Roger L. Bagula, Nov 12 2003

Keywords

Comments

a(n)=n if Q(n) > Q(n-1), and a(n) =1 if Q(n) <= Q(n-1).

Crossrefs

Programs

  • Mathematica
    Hofstadter[n_Integer?Positive] := Hofstadter[n] = Hofstadter[n - Hofstadter[n-1]] + Hofstadter[n - Hofstadter[n-2]] Hofstadter[1] = Hofstadter[2] = 1 digits=200 a=Table[If[Hofstadter[n]-Hofstadter[n-1]>0, n, 1], {n, 2, digits}]

Formula

a(n) = n if A081827(n-1)>0; a(n) = 1 if A081827(n-1) <=0. [R. J. Mathar, Dec 08 2010]
Showing 1-6 of 6 results.