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.

A005228 Sequence and first differences (A030124) together list all positive numbers exactly once.

This page as a plain text file.
%I A005228 M2629 #156 Jun 30 2025 06:04:12
%S A005228 1,3,7,12,18,26,35,45,56,69,83,98,114,131,150,170,191,213,236,260,285,
%T A005228 312,340,369,399,430,462,495,529,565,602,640,679,719,760,802,845,889,
%U A005228 935,982,1030,1079,1129,1180,1232,1285,1339,1394,1451,1509,1568,1628,1689
%N A005228 Sequence and first differences (A030124) together list all positive numbers exactly once.
%C A005228 This is the lexicographically earliest sequence that together with its first differences (A030124) contains every positive integer exactly once.
%C A005228 Hofstadter introduces this sequence in his discussion of Scott Kim's "FIGURE-FIGURE" drawing. - _N. J. A. Sloane_, May 25 2013
%C A005228 A225850(a(n)) = 2*n-1, cf. A167151. - _Reinhard Zumkeller_, May 17 2013
%C A005228 In view of the definition of A075326: start with a(0) = 0, and extend by rule that the next term is the sum of the predecessor and the most recent non-member of the sequence. - _Reinhard Zumkeller_, Oct 26 2014
%D A005228 E. Angelini, "Jeux de suites", in Dossier Pour La Science, pp. 32-35, Volume 59 (Jeux math'), April/June 2008, Paris.
%D A005228 D. R. Hofstadter, Goedel, Escher, Bach: an Eternal Golden Braid, Random House, 1980, p. 73.
%D A005228 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).
%H A005228 N. J. A. Sloane, <a href="/A005228/b005228.txt">Table of n, a(n) for n = 1..10001</a> [The first 1000 terms were computed by T. D. Noe]
%H A005228 A. S. Fraenkel, <a href="http://www.emis.de/journals/INTEGERS/papers/eg6/eg6.Abstract.html">New games related to old and new sequences</a>, INTEGERS, Electronic J. of Combinatorial Number Theory, Vol. 4, Paper G6, 2004.
%H A005228 Catalin Francu, <a href="/A005228/a005228.txt">C++ program</a>
%H A005228 Cristian Francu, <a href="/A005228/a005228_1.txt">C program to generate the N-th element in O(sqrt(N))</a>
%H A005228 D. R. Hofstadter, <a href="/A006336/a006336_1.pdf">Eta-Lore</a> [Cached copy, with permission]
%H A005228 D. R. Hofstadter, <a href="/A006336/a006336_2.pdf">Pi-Mu Sequences</a> [Cached copy, with permission]
%H A005228 D. R. Hofstadter and N. J. A. Sloane, <a href="/A006336/a006336.pdf">Correspondence, 1977 and 1991</a>
%H A005228 Benoit Jubin, <a href="http://www.emis.de/journals/JIS/VOL17/Jubin/jubin2.html">Asymptotic series for Hofstadter's figure-figure sequences</a>, <a href="http://arxiv.org/abs/1404.1791">arXiv:1404.1791</a>; J. Integer Sequences, 17 (2014), #14.7.2.
%H A005228 Clark Kimberling, <a href="https://cs.uwaterloo.ca/journals/JIS/VOL10/Kimberling/kimberling26.html">Complementary Equations</a>, Journal of Integer Sequences, Vol. 10 (2007), Article 07.1.4.
%H A005228 N. J. A. Sloane, <a href="http://neilsloane.com/doc/sg.txt">My favorite integer sequences</a>, in Sequences and their Applications (Proceedings of SETA '98).
%H A005228 David Singmaster, <a href="/A005178/a005178.pdf">Letter to N. J. A. Sloane</a>, Oct 3 1982.
%H A005228 Eric Weisstein's World of Mathematics, <a href="https://mathworld.wolfram.com/HofstadterFigure-FigureSequence.html">Hofstadter Figure-Figure Sequence</a>.
%H A005228 <a href="/index/Go#GEB">Index entries for sequences from "Goedel, Escher, Bach"</a>
%H A005228 <a href="/index/Ho#Hofstadter">Index entries for Hofstadter-type sequences</a>
%F A005228 a(n) = a(n-1) + c(n-1) for n >= 2, where a(1)=1, a( ) increasing, c( ) = complement of a( ) (c is the sequence A030124).
%F A005228 Let a(n) = this sequence, b(n) = A030124 prefixed by 0. Then b(n) = mex{ a(i), b(i) : 0 <= i < n}, a(n) = a(n-1) + b(n) + 1. (Fraenkel)
%F A005228 a(1) = 1, a(2) = 3; a( ) increasing; for n >= 3, if a(q) = a(n-1)-a(n-2)+1 for some q < n then a(n) = a(n-1) + (a(n-1)-a(n-2)+2), otherwise a(n) = a(n-1) + (a(n-1)-a(n-2)+1). - Albert Neumueller (albert.neu(AT)gmail.com), Jul 29 2006
%F A005228 a(n) = n^2/2 + n^(3/2)/(3*sqrt(2)) + O(n^(5/4)) [proved in Jubin link]. - _Benoit Jubin_, May 13 2015
%F A005228 For all n >= 1, A232746(a(n)) = n and A232747(a(n)) = n. [Both sequences work as left inverses of this sequence.] - _Antti Karttunen_, May 14 2015
%e A005228 Sequence reads 1 3 7 12 18 26 35 45..., differences are 2 4 5, 6, 8, 9, 10 ... and the point is that every number not in the sequence itself appears among the differences. This property (together with the fact that both the sequence and the sequence of first differences are increasing) defines the sequence!
%p A005228 maxn := 5000; h := array(1..5000); h[1] := 1; a := [1]; i := 1; b := []; for n from 2 to 1000 do if h[n] <> 1 then b := [op(b), n]; j := a[i]+n; if j < maxn then a := [op(a),j]; h[j] := 1; i := i+1; fi; fi; od: a; b; # a is A005228, b is A030124.
%p A005228 A030124 := proc(n)
%p A005228     option remember;
%p A005228     local a,fnd,t ;
%p A005228     if n <= 1 then
%p A005228         op(n+1,[2,4]) ;
%p A005228     else
%p A005228         for a from procname(n-1)+1 do
%p A005228             fnd := false;
%p A005228             for t from 1 to n+1 do
%p A005228                 if A005228(t)  = a then
%p A005228                     fnd := true;
%p A005228                     break;
%p A005228                 end if;
%p A005228             end do:
%p A005228             if not fnd then
%p A005228                 return a;
%p A005228             end if;
%p A005228         end do:
%p A005228     end if;
%p A005228 end proc:
%p A005228 A005228 := proc(n)
%p A005228     option remember;
%p A005228     if n <= 2 then
%p A005228         op(n,[1,3]) ;
%p A005228     else
%p A005228         procname(n-1)+A030124(n-2) ;
%p A005228     end if;
%p A005228 end proc: # _R. J. Mathar_, May 19 2013
%t A005228 a = {1}; d = 2; k = 1; Do[ While[ Position[a, d] != {}, d++ ]; k = k + d; d++; a = Append[a, k], {n, 1, 55} ]; a
%t A005228 (* Second program: *)
%t A005228 (* Program from Larry Morris, Jan 19 2017: *)
%t A005228 d = 3; a = {1, 3, 7, 12, 18}; While[ Length[a = Join[a, a[[-1]] + Accumulate[Range[a[[d]] + 1, a[[++d]] - 1]]]] < 50]; a
%t A005228 (* Comment: This adds as many terms to the sequence as there are numbers in each set of sequential differences. Consequently, the list of numbers it produces may be longer than the limit provided. With the limit of 50 shown, the sequence produced has length 60. *)
%o A005228 (Haskell)
%o A005228 a005228 = scanl (+) 1 a030124
%o A005228 a030124 = go 1 a005228 where go x ys | x < head ys = x     : go (x + 1) ys
%o A005228                                      | otherwise   = x + 1 : go (x + 2) (tail ys)
%o A005228 -- Maks Verver, Jun 30 2025
%o A005228 (PARI) A005228(n,print_all=0,s=1,used=0)={while(n--,used += 1<<s; print_all & print1(s","); for(k=s+1,9e9, bittest(used,k) & next; bittest(used, k-s) & next; used += 1<<(k-s); s=k; break));s} \\ _M. F. Hasler_, Feb 05 2013
%Y A005228 Cf. A030124 (complement), A037257, A056731, A056738, A140778, A225687.
%Y A005228 The following are a group of related sequences: A005132, A006509, A037257, A037258, A037259, A081145, A093903, A099004, A100707, A129198, A129199, A140778, A225376, A225377, A225378, A225385, A225386, A225387.
%Y A005228 Cf. A075326, A095115.
%Y A005228 Cf. A225850, A232746, A232747 (inverse), A232739, A232740, A232750 and also permutation pair A232751/A232752 constructed from this sequence and its complement.
%Y A005228 Cf. A001651 (analog with sums instead of differences), A121229 (analog with products).
%Y A005228 The same recurrence a(n) = a(n-1) + c(n-1) with different starting conditions: A061577 (starting with 2), A022935 (3), A022936 (4), A022937 (5), A022938 (6).
%Y A005228 Related recurrences:
%Y A005228 a(n-1) + c(n+1) - A022953, A022954.
%Y A005228 a(n-1) + c(n) - A022946 to A022952.
%Y A005228 a(n-1) + c(n-2) - A022940, A022941.
%Y A005228 a(n-2) + c(n-1) - A022942 to A022944.
%Y A005228 a(n-2) + c(n-2) - A022939.
%Y A005228 a(n-3) + c(n-3) - A022955.
%Y A005228 a(n-4) + c(n-4) - A022956.
%Y A005228 a(n-5) + c(n-5) - A022957.
%K A005228 nonn,easy,nice
%O A005228 1,2
%A A005228 _N. J. A. Sloane_
%E A005228 Additional comments from _Robert G. Wilson v_, Oct 24 2001
%E A005228 Incorrect formula removed by _Benoit Jubin_, May 13 2015