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-10 of 19 results. Next

A005132 Recamán's sequence (or Recaman's sequence): a(0) = 0; for n > 0, a(n) = a(n-1) - n if nonnegative and not already in the sequence, otherwise a(n) = a(n-1) + n.

Original entry on oeis.org

0, 1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 42, 17, 43, 16, 44, 15, 45, 14, 46, 79, 113, 78, 114, 77, 39, 78, 38, 79, 37, 80, 36, 81, 35, 82, 34, 83, 33, 84, 32, 85, 31, 86, 30, 87, 29, 88, 28, 89, 27, 90, 26, 91, 157, 224, 156, 225, 155
Offset: 0

Views

Author

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

Keywords

Comments

The name "Recamán's sequence" is due to N. J. A. Sloane, not the author!
I conjecture that every number eventually appears - see A057167, A064227, A064228. - N. J. A. Sloane. That was written in 1991. Today I'm not so sure that every number appears. - N. J. A. Sloane, Feb 26 2017
As of Jan 25 2018, the first 13 missing numbers are 852655, 930058, 930557, 964420, 966052, 966727, 969194, 971330, 971626, 971866, 972275, 972827, 976367, ... For further information see the "Status Report" link. - Benjamin Chaffin, Jan 25 2018
From David W. Wilson, Jul 13 2009: (Start)
The sequence satisfies [1] a(n) >= 0, [2] |a(n)-a(n-1)| = n, and tries to avoid repeats by greedy choice of a(n) = a(n-1) -+ n.
This "wants" to be an injection on N = {0, 1, 2, ...}, as it attempts to avoid repeats by choice of a(n) = a(n-1) + n when a(n) = a(n-1) - n is a repeat.
Clearly, there are injections satisfying [1] and [2], e.g., a(n) = n(n+1)/2.
Is there a lexicographically earliest injection satisfying [1] and [2]? (End)
Answer: Yes, of course: The set of injections satisfying [1] and [2] is not empty, so there's a lexicographically least element. More concretely, it starts with the same 23 terms a(0..22) which are known to be minimal, but after a(22) = 41 it has to go on with a(23) = 41 + 23 = 64, since choosing "-" here necessarily yields a non-injective sequence. See A171884. - M. F. Hasler, Apr 01 2019
It appears that a(n) is also the value of "x" and "y" of the endpoint of the L-toothpick structure mentioned in A210606 after n-th stage. - Omar E. Pol, Mar 24 2012
Of course this is not a permutation of the integers: the first repeated term is 42 = a(24) = a(20). - M. F. Hasler, Nov 03 2014. Also 43 = a(18) = a(26). - Jon Perry, Nov 06 2014
Of all the sequences in the OEIS, this one is my favorite to listen to. Click the "listen" button at the top, set the instrument to "103. FX 7 (Echoes)", click "Save", and open the MIDI file with a program like QuickTime Player 7. - N. J. A. Sloane, Aug 08 2017
This sequence cycles clockwise around the OEIS logo. - Ryan Brooks, May 09 2020

Examples

			Consider n=6. We have a(5)=7 and try to subtract 6. The result, 1, is certainly positive, but we cannot use it because 1 is already in the sequence. So we must add 6 instead, getting a(6) = 7 + 6 = 13.
		

References

  • Alex Bellos and Edmund Harriss, Visions of the Universe (2016), Unnumbered pages. Includes Harriss's illustration of the first 65 steps drawn as a spiral.
  • Benjamin Chaffin, N. J. A. Sloane, and Allan Wilks, On sequences of Recaman type, paper in preparation, 2006.
  • Bernardo Recamán Santos, letter to N. J. A. Sloane, Jan 29 1991
  • N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences, Academic Press, 1995 (includes this sequence).

Crossrefs

Cf. A057165 (addition steps), A057166 (subtraction steps), A057167 (steps to hit n), A008336, A046901 (simplified version), A064227 (records for reaching n), A064228 (value of n that take a record number of steps to reach), A064284 (no. of times n appears), A064290 (heights of terms), A064291 (record highs), A119632 (condensed version), A063733, A079053, A064288, A064289, A064387, A064388, A064389, A228474 (bidirectional version).
A065056 gives partial sums, A160356 gives first differences.
A row of A066201.
Cf. A171884 (injective variant).
See A324784, A324785, A324786 for the "low points".

Programs

  • Haskell
    import Data.Set (Set, singleton, notMember, insert)
    a005132 n = a005132_list !! n
    a005132_list = 0 : recaman (singleton 0) 1 0 where
       recaman :: Set Integer -> Integer -> Integer -> [Integer]
       recaman s n x = if x > n && (x - n) `notMember` s
                          then (x-n) : recaman (insert (x-n) s) (n+1) (x-n)
                          else (x+n) : recaman (insert (x+n) s) (n+1) (x+n)
    -- Reinhard Zumkeller, Mar 14 2011
    
  • MATLAB
    function a=A005132(m)
    % m=max number of terms in a(n). Offset n:0
    a=zeros(1,m);
    for n=2:m
        B=a(n-1)-(n-1);
        C=0.^( abs(B+1) + (B+1) );
        D=ismember(B,a(1:n-1));
        a(n)=a(n-1)+ (n-1) * (-1)^(C + D -1);
    end
    % Adriano Caroli, Dec 26 2010
    
  • Maple
    h := array(1..100000); maxt := 100000; a := [1]; ad := [1]; su := []; h[1] := 1; for nx from 2 to 500 do t1 := a[nx-1]-nx; if t1>0 and h[t1] <> 1 then su := [op(su), nx]; else t1 := a[nx-1]+nx; ad := [op(ad), nx]; fi; a := [op(a),t1]; if t1 <= maxt then h[t1] := 1; fi; od: # a is A005132, ad is A057165, su is A057166
    A005132 := proc(n)
        option remember; local a, found, j;
        if n = 0 then return 0 fi;
        a := procname(n-1) - n ;
        if a <= 0 then return a+2*n fi;
        found := false;
        for j from 0 to n-1 while not found do
            found := procname(j) = a;
        od;
        if found then a+2*n else a fi;
    end:
    seq(A005132(n), n=0..70); # R. J. Mathar, Apr 01 2012 (reformatted by Peter Luschny, Jan 06 2019)
  • Mathematica
    a = {1}; Do[ If[ a[ [ -1 ] ] - n > 0 && Position[ a, a[ [ -1 ] ] - n ] == {}, a = Append[ a, a[ [ -1 ] ] - n ], a = Append[ a, a[ [ -1 ] ] + n ] ], {n, 2, 70} ]; a
    (* Second program: *)
    f[s_List] := Block[{a = s[[ -1]], len = Length@s}, Append[s, If[a > len && !MemberQ[s, a - len], a - len, a + len]]]; Nest[f, {0}, 70] (* Robert G. Wilson v, May 01 2009 *)
    RecamanSeq[i_Integer] := Fold[With[{lst=Last@#, len=Length@#}, Append[#, If[lst > len && !MemberQ[#, lst - len], lst - len, lst + len]]] &, {0}, Range@i]; RecamanSeq[10^5] (* Mikk Heidemaa, Nov 02 2024 *)
  • PARI
    a(n)=if(n<2,1,if(abs(sign(a(n-1)-n)-1)+setsearch(Set(vector(n-1,i,a(i))),a(n-1)-n),a(n-1)+n,a(n-1)-n))  \\ Benoit Cloitre
    
  • PARI
    A005132(N=1000,show=0)={ my(s,t); for(n=1,N, s=bitor(s,1<M. F. Hasler, May 11 2008, updated M. F. Hasler, Nov 03 2014
    
  • Python
    l=[0]
    for n in range(1, 101):
        x=l[n - 1] - n
        if x>0 and not x in l: l+=[x, ]
        else: l+=[l[n - 1] + n]
    print(l) # Indranil Ghosh, Jun 01 2017
    
  • Python
    def recaman(n):
      seq = []
      for i in range(n):
        if(i == 0): x = 0
        else: x = seq[i-1]-i
        if(x>=0 and x not in seq): seq+=[x]
        else: seq+=[seq[i-1]+i]
      return seq
    print(recaman(1000)) # Ely Golden, Jun 14 2018
    
  • Python
    from itertools import count, islice
    def A005132_gen(): # generator of terms
        a, aset = 0, set()
        for n in count(1):
            yield a
            aset.add(a)
            a = b if (b:=a-n)>=0 and b not in aset else a+n
    A005132_list = list(islice(A005132_gen(),30)) # Chai Wah Wu, Sep 15 2022

Formula

a(k) = A000217(k) - 2*Sum_{i=1..n} A057166(i), for A057166(n) <= k < A057166(n+1). - Christopher Hohl, Jan 27 2019

Extensions

Allan Wilks, Nov 06 2001, computed 10^15 terms of this sequence. At this point all the numbers below 852655 had appeared, but 852655 = 5*31*5501 was missing.
After 10^25 terms of A005132 the smallest missing number is still 852655. - Benjamin Chaffin, Jun 13 2006
Even after 7.78*10^37 terms, the smallest missing number is still 852655. - Benjamin Chaffin, Mar 28 2008
Even after 4.28*10^73 terms, the smallest missing number is still 852655. - Benjamin Chaffin, Mar 22 2010
Even after 10^230 terms, the smallest missing number is still 852655. - Benjamin Chaffin, 2018
Changed "positive" in definition to "nonnegative". - N. J. A. Sloane, May 04 2020

A064290 First number of height n in Recamán's sequence A005132.

Original entry on oeis.org

0, 1, 3, 6, 13, 20, 43, 62, 113, 224, 367, 494, 833, 1815, 3379, 5551, 9169, 17864, 32978, 58964, 106218, 131313, 155719, 180118, 591890, 881467, 1345004, 3012446, 5728819, 9309579, 17512700, 25641318, 52978675, 61998980, 125130665, 244636214, 280766754, 566273517, 1031389697, 2182394227, 3045423658, 3454917187
Offset: 1

Views

Author

N. J. A. Sloane, Sep 25 2001

Keywords

Comments

The height of a term in A005132 = number of addition steps - number of subtraction steps to reach it (see A064289).
Needs a b-file. - N. J. A. Sloane, May 01 2020

Examples

			A005132 begins 0, 1, 3, 6, 2, 7, 13, 20, 12, ... and these terms have heights 0, 1, 2, 3, 2, 3, 4, 5, 4, ...
		

Crossrefs

Extensions

a(0) = 0 added by N. J. A. Sloane, May 01 2020

A210606 Length of the n-th edge of an L-toothpick structure which gives Recamán's sequence A005132.

Original entry on oeis.org

1, 3, 5, 3, 4, 4, 5, 11, 13, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 16, 16, 17, 17
Offset: 1

Views

Author

Omar E. Pol, Mar 24 2012

Keywords

Comments

Consider a toothpick structure formed by L-toothpicks connected by their endpoints. The endpoints of the L-toothpicks are placed on the main diagonal of the first quadrant. At stage 1 we place an L-toothpick with one of its endpoints on the origin. At stage n we place an L-toothpick of size n. The L-toothpicks are placed alternately, on one or another sector of the first quadrant, trying to make the structure have an exposed endpoint closest to the origin. The total length of all L-toothpicks after the n-th stage is A002378(n). The value of x and y of the endpoint of the structure after the n-th stage is equal to the n-th term of Recamán's sequence A005132(n). Note that we can get other illustrations of initial terms of Recamán's sequence by replacing each L-toothpick by a Q-toothpick or by a semicircumference. This structure is also one of the three views of the three-dimensional model for Recamán's sequence. For more information about L-toothpicks and Q-toothpicks, see A172310 and A187210.

Examples

			The summands are the size of the L-toothpicks:
a(1) = 1.
a(2) = 1 + 2 = 3.
a(3) = 2 + 3 = 5.
a(4) = 3.
a(5) = 4.
a(6) = 4.
a(7) = 5.
a(8) = 5 + 6 = 11.
a(9) = 6 + 7 = 13.
a(10) = 7.
		

Crossrefs

A064288 Height of n when it appears for first time in Recamán's sequence A005132.

Original entry on oeis.org

0, 1, 2, 2, 7, 7, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 18, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 19, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 19, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9
Offset: 0

Views

Author

N. J. A. Sloane, Sep 25 2001

Keywords

Comments

The height of a term in A005132 = number of addition steps - number of subtraction steps to produce it (see A064289).

Examples

			A005132 begins 0, 1, 3, 6, 2, 7, 13, 20, 12, ... and these terms have heights 0, 1, 2, 3, 2, 3, 4, 5, 4, ...
		

Crossrefs

Programs

  • C
    See Links section.

Extensions

a(0)=0 added by N. J. A. Sloane, May 01 2020

A064387 Variation (2) on Recamán's sequence (A005132): to get a(n), we first try to subtract n from a(n-1): a(n) = a(n-1)-n if positive and not already in the sequence; if not then a(n) = a(n-1)+n+i, where i >= 0 is the smallest number such that a(n-1)+n+i has not already appeared.

Original entry on oeis.org

1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 44, 19, 45, 72, 100, 71, 101, 70, 38, 5, 39, 4, 40, 77, 115, 76, 36, 78, 120, 163, 119, 74, 28, 75, 27, 79, 29, 80, 132, 185, 131, 186, 130, 73, 15, 81, 141, 202
Offset: 1

Views

Author

N. J. A. Sloane, Sep 28 2001

Keywords

Comments

Variation (4) (A064389) is the nicest of these variations.
I would also like to get the following sequences: number of steps before n appears (or 0 if n never appears), list of numbers that never appear, height of n (cf. A064288, A064289, A064290), etc.

References

  • Suggested by J. C. Lagarias.

Crossrefs

Cf. A005132, A046901, A064388, A064389. Agrees with A064389 for first 187 terms, then diverges.

Programs

  • Maple
    h := array(1..100000); maxt := 100000; a := array(1..1000); a[1] := 1; h[1] := 1; for nx from 2 to 1000 do t1 := a[nx-1]-nx; if t1>0 and h[t1] <> 1 then a[nx] := t1; if t1 < maxt then h[t1] := 1; fi; else for i from 0 to 1000 do t1 := a[nx-1]+nx+i; if h[t1] <> 1 then a[nx] := t1; if t1 < maxt then h[t1] := 1; fi; break; fi; od; fi; od; evalm(a);

A064388 Variation (3) on Recamán's sequence (A005132): set s (the step size) initially equal to 2; to get a(n), we first try to subtract s from a(n-1): a(n) = a(n-1)-s if positive and not already in the sequence, in which case we change s to s+1; if not, a(n) = a(n-1)+s+i, where i >= 0 is the smallest number such that a(n-1)+s+i has not already appeared and now we change s to s+i+1.

Original entry on oeis.org

1, 3, 6, 2, 7, 13, 20, 12, 21, 11, 22, 10, 23, 9, 24, 8, 25, 43, 62, 42, 63, 41, 18, 44, 17, 45, 16, 46, 15, 47, 14, 48, 83, 119, 82, 120, 81, 121, 80, 38, 84, 37, 85, 36, 86, 35, 87, 34, 88, 33, 89, 32, 90, 31, 91, 30, 92, 29, 93, 28, 94, 27, 95, 26, 96, 167, 239, 166, 240
Offset: 1

Views

Author

N. J. A. Sloane, Sep 28 2001

Keywords

Comments

Variation (4) (A064389) is the nicest of these variations.
I would also like to get the following sequences: number of steps before n appears (or 0 if n never appears), list of numbers that never appear, height of n (cf. A064288, A064289, A064290), etc.

Crossrefs

Programs

  • BASIC
    rem Chipmunk BASIC v3.6.4(b8) http://www.nicholson.com/rhn/basic/
    max=1000 : dim a(max)
    s=2 : z=1 : a(z)=1 : print str$(z)+",";
    for n=1 to 200
    x=z-s : if x <= 0 then goto yyy
    if a(x)=0 then a(x)=1 : print str$(x)+","; : s=s+1 : z=x : goto xxx
    yyy: for i=0 to max
    x=z+s+i
    if a(x)=0 then a(x)=1 : print str$(x)+","; : s=s+i+1 : z=x : goto xxx
    next i
    xxx: next n
    print : end
    rem Jeremy Gardiner, Feb 22 2014

Extensions

More terms from David Wasserman, Jul 16 2002

A064291 Record high values in Recamán's sequence A005132.

Original entry on oeis.org

0, 1, 3, 6, 7, 13, 20, 21, 22, 23, 24, 25, 43, 62, 63, 79, 113, 114, 157, 224, 225, 226, 227, 228, 265, 367, 368, 369, 370, 379, 494, 495, 631, 632, 633, 634, 635, 636, 643, 833, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1182, 1183
Offset: 0

Views

Author

N. J. A. Sloane, Sep 25 2001

Keywords

Crossrefs

Extensions

a(0)=0 added by N. J. A. Sloane, May 01 2020

A064492 Start of n-th segment of Recamán's sequence R(m) (A005132): values of n where the change in the fractional parts of successive values of R(n)/n is positive.

Original entry on oeis.org

1, 2, 4, 7, 12, 22, 40, 77, 135, 249, 454, 845, 1521, 2753, 5046, 9318, 17224, 31222, 57072, 99742, 181694, 328256, 589933, 1034839, 1788538, 3225919, 5784586, 10212211, 18399785, 32148795, 58056876, 101769230, 173395920, 302890749, 511561221, 904036925, 1610187039, 2789150424, 4910758398, 8416580355, 13808215356, 23006557539, 39488697701, 65854567303, 107078836274, 188471115227, 325374626149, 535755688022, 872467803894, 1404720439054, 2402964238974, 3883018238330, 6283167591180, 10125357598983, 16166305650061, 25735985498862, 40806937801473, 64628644387495, 102481019573338, 159888464280047, 250759470174414, 394178473635589, 599819882554936, 939455761022725
Offset: 1

Views

Author

John W. Layman, Oct 04 2001

Keywords

Crossrefs

Cf. A005132, A064288, A064289, A064292, A064293. This sequence and A064294 keep pretty close together.
See A065038 for the corresponding values of R(n). See also A065053 for first differences.

Extensions

More terms from John W. Layman and N. J. A. Sloane, Oct 12 2001
Extended to 10^15 by Allan Wilks, Nov 06 2001

A269830 Number of terms of height n in Recamán's sequence A005132.

Original entry on oeis.org

1, 2, 2, 6, 11, 22, 34, 61, 115, 220, 397, 681, 1329, 2430, 4561, 8116, 14848, 24878
Offset: 1

Views

Author

Danny Rorabaugh, Mar 05 2016

Keywords

Comments

The height (A064289) of a term in Recamán's sequence (A005132) = number of addition steps - number of subtraction steps to produce it.

Crossrefs

A366912 Partial sums of A366911: a(1) = 0, and for n > 0, a(n+1) = a(n) + A366911(n).

Original entry on oeis.org

0, 1, 2, 3, 2, 3, 2, 3, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 4, 5, 6, 5, 6, 5, 6, 7, 8, 5, 7, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 7, 8, 6, 7, 8, 9, 8, 9, 8
Offset: 1

Views

Author

Rémy Sigrist, Oct 27 2023

Keywords

Comments

By analogy with A064289, a(n) corresponds to the height of A364054(n) = number of addition steps - number of subtraction steps to produce it.

Examples

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

Crossrefs

Programs

  • Mathematica
    nn = 2^16; c[] := False; m[] := 0; j = 1; s = b[1] = 0;
      c[0] = c[1] = True;
      Monitor[Do[p = Prime[n - 1]; r = Mod[j, p];
        While[Set[k, p m[p] + r ]; c[k], m[p]++]; s += (k - j)/p;
        Set[{a[n - 1], b[n - 1], c[k], j}, {(k - j)/p, s, True, k}],
        {n, 2, nn + 1}], n];
    Array[b, nn] (* Michael De Vlieger, Oct 27 2023 *)
  • PARI
    See Links section.
    
  • Python
    from itertools import count, islice
    from sympy import nextprime
    def A366912_gen(): # generator of terms
        a, aset, p, c = 1, {0,1}, 2, 0
        while True:
            k, b = divmod(a,p)
            for i in count(-k):
                if b not in aset:
                    aset.add(b)
                    a, p = b, nextprime(p)
                    yield c
                    c += i
                    break
    A366912_list = list(islice(A366912_gen(),30)) # Chai Wah Wu, Oct 27 2023

Formula

a(n) = Sum_{k = 1..n-1} A366911(k).
Showing 1-10 of 19 results. Next