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 15 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

A008344 a(1)=0; thereafter a(n+1) = a(n) - n if a(n) >= n otherwise a(n+1) = a(n) + n.

Original entry on oeis.org

0, 1, 3, 0, 4, 9, 3, 10, 2, 11, 1, 12, 0, 13, 27, 12, 28, 11, 29, 10, 30, 9, 31, 8, 32, 7, 33, 6, 34, 5, 35, 4, 36, 3, 37, 2, 38, 1, 39, 0, 40, 81, 39, 82, 38, 83, 37, 84, 36, 85, 35, 86, 34, 87, 33, 88, 32, 89, 31, 90, 30, 91, 29, 92, 28, 93, 27, 94, 26, 95, 25, 96, 24, 97, 23, 98
Offset: 1

Views

Author

Keywords

Comments

p^a(n) = A084110(p^(n-1)) for n>1 and p prime. - Reinhard Zumkeller, May 12 2003
For n > 1: a(A029858(n)) = A029858(n) and a(A003462(n)) = 0. - Reinhard Zumkeller, May 09 2012
Absolute first differences of A085059; abs(a(n+1)-a(n)) = n, see also A086283. - Reinhard Zumkeller, Oct 17 2014
For n>3, when a(n) = 3, a(n+1) is in A116970. - Bill McEachen, Oct 03 2023

Crossrefs

Equals A085059(n)-1.
Cf. A076042 (based on squares).

Programs

  • Haskell
    a008344 n = a008344_list !! (n-1)
    a008344_list = 0 : f 0 [1..] where
       f x (z:zs) = y : f y zs where y = if x < z then x + z else x - z
    -- Reinhard Zumkeller, Oct 17 2014, May 08 2012
    
  • Maple
    A008344 := proc(n) option remember; if n = 0 then 0 elif A008344(n-1) >= (n-1) then A008344(n-1)-(n-1) else A008344(n-1)+(n-1); fi; end;
  • Mathematica
    a[1]=0; a[n_] := a[n]=If[a[n-1]>=n-1, a[n-1]-n+1, a[n-1]+n-1]
    Transpose[ NestList[ If[First[#]>=Last[#],{First[#]-Last[#],Last[#]+1}, {First[#]+Last[#],Last[#]+1}]&,{0,1},80]][[1]] (* Harvey P. Dale, Jun 20 2011 *)
    s = 0; Table[If[s < n, s = s + n, s = s - n], {n, 0, 80}] (* Horst H. Manninger, Dec 03 2018 *)
  • PARI
    a(n) = my(expo = logint(2*n+1, 3), res = n - (3^expo-1)/2); if(res==0, 0, if(res%2, (3^expo-res)/2, 3^expo-1+res/2)) \\ Jianing Song, May 25 2021

Formula

This is a concatenation S_0, S_1, S_2, ... where S_i = [b_0, b_1, ..., b_{3^(i+1)-1}] with b_0 = 0, b_{2j-1} = k+1-j, b_{2j} = 2k+j (j=1..k), k=(3^(i+1)-1)/2. E.g. S_0 = [0, 1, 3], S_1 = [0, 4, 9, 3, 10, 2, 11, 1, 12].
a((3^n-1)/2) = 0; a((3^n-1)/2 + 2k-1) = (3^n+1)/2 - k for 1 <= k <= (3^n-1)/2; a((3^n-1)/2 + 2k) = 3^n - 1 + k for 1 <= k < (3^n-1)/2. - Benoit Cloitre, Jan 09 2003 [Corrected by Jianing Song, May 25 2021]
a(n) = (n-1+a(n-1)) mod (2*(n-1)). - Jon Maiga, Jul 09 2021

Extensions

Name edited by Dmitry Kamenetsky, Feb 14 2017

A076042 a(0) = 0; thereafter a(n) = a(n-1) + n^2 if a(n-1) < n^2, otherwise a(n) = a(n-1) - n^2.

Original entry on oeis.org

0, 1, 5, 14, 30, 5, 41, 90, 26, 107, 7, 128, 272, 103, 299, 74, 330, 41, 365, 4, 404, 845, 361, 890, 314, 939, 263, 992, 208, 1049, 149, 1110, 86, 1175, 19, 1244, 2540, 1171, 2615, 1094, 2694, 1013, 2777, 928, 2864, 839, 2955, 746, 3050, 649, 3149
Offset: 0

Views

Author

Amarnath Murthy, Oct 29 2002

Keywords

Comments

Does not return to zero within first 2^25000 =~ 10^7525 terms. Define an epoch as an addition followed by a sequence of (addition, subtraction) pairs. The first epoch has length 1 (+), the second 3 (++-), the third 5 (++-+-), and so forth (cf. A324792). The epoch lengths increase geometrically by about the square root of 3, and the value at the end of each epoch is the low value in the epoch. These observations lead to the Python program given. - Tomas Rokicki, Aug 31 2019
Using the Maple program in A324791, I confirmed that a(n) != 0 for 0 < n < 10^2394. See the a- and b-files in A325056 and A324791. - N. J. A. Sloane, Oct 03 2019
'Easy Recamán transform' of the squares. - Daniel Forgues, Oct 25 2019

Crossrefs

See also A325056, A324791, A324792.
Cf. A053461 ('Recamán transform' of the squares).

Programs

  • Maple
    a:= proc(n) option remember; `if`(n<0, 0,
          ((s, t)-> s+`if`(sAlois P. Heinz, Jan 11 2020
  • Mathematica
    a[0] = 0;
    a[n_] := a[n] = a[n-1] + If[a[n-1] < n^2, n^2, -n^2];
    a /@ Range[0, 50] (* Jean-François Alcover, Apr 11 2020 *)
  • PARI
    v=vector(50); v[1]=1; for(n=2,50,if(v[n-1]
    				

Extensions

More terms from Ralf Stephan, Mar 20 2003
a(0)=0 prepended, at the suggestion of Allan C. Wechsler, by N. J. A. Sloane, Aug 31 2019
Offset set to 0, to cohere with previous action of N. J. A. Sloane, by Allan C. Wechsler, Sep 08 2019

A134931 a(n) = (5*3^n-3)/2.

Original entry on oeis.org

1, 6, 21, 66, 201, 606, 1821, 5466, 16401, 49206, 147621, 442866, 1328601, 3985806, 11957421, 35872266, 107616801, 322850406, 968551221, 2905653666, 8716961001, 26150883006, 78452649021, 235357947066, 706073841201, 2118221523606
Offset: 0

Views

Author

Rolf Pleisch, Jan 29 2008

Keywords

Comments

Numbers n where the recurrence s(0)=1, if s(n-1) >= n then s(n) = s(n-1) - n else s(n) = s(n-1) + n produces s(n)=0. - Hugo Pfoertner, Jan 05 2012
A046901(a(n)) = 1. - Reinhard Zumkeller, Jan 31 2013
Binomial transform of A146523: (1, 5, 10, 20, 40, ...) and double binomial transform of A010685: (1, 4, 1, 4, 1, 4, ...). - Gary W. Adamson, Aug 25 2016
Also the number of maximal cliques in the (n+1)-Hanoi graph. - Eric W. Weisstein, Dec 01 2017
a(n) is the least k such that f(a(n-1)+1) + ... + f(k) > f(a(n-2)+1) + ... + f(a(n-1)) for n > 1, where f(n) = 1/(n+1). Because Sum_{k=1..5*3^(n-1)} 1/(a(n)+3*k-1) + 1/(a(n)+3*k) + 1/(a(n)+3*k+1) - 1/((a(n)+1+5*3^n)*5*3^(n-1)) < Sum_{k=1..5*3^(n-1)} 1/(a(n-1)+k+1) < Sum_{k=1..5*3^(n-1)} 1/(a(n)+3*k-1) + 1/(a(n)+3*k) + 1/(a(n)+3*k+1), we have 1 < 1/3 + 1/4 + ... + 1/7 < 1/8 + 1/9 + ... + 1/22 < ... . - Jinyuan Wang, Jun 15 2020

Crossrefs

Programs

Formula

a(n) = 3*(a(n-1) + 1), with a(0)=1.
From R. J. Mathar, Jan 31 2008: (Start)
O.g.f.: (5/2)/(1-3*x) - (3/2)/(1-x).
a(n) = (A005030(n) - 3)/2. (End)
a(n) = A060816(n+1) - 1. - Philippe Deléham, Apr 14 2013
E.g.f.: exp(x)*(5*exp(2*x) - 3)/2. - Stefano Spezia, Aug 28 2023

Extensions

More terms from Vladimir Joseph Stephan Orlovsky, Dec 25 2008

A057198 a(n) = (5*3^(n-1)+1)/2.

Original entry on oeis.org

3, 8, 23, 68, 203, 608, 1823, 5468, 16403, 49208, 147623, 442868, 1328603, 3985808, 11957423, 35872268, 107616803, 322850408, 968551223, 2905653668, 8716961003, 26150883008, 78452649023, 235357947068, 706073841203, 2118221523608
Offset: 1

Views

Author

Colin Mallows and N. J. A. Sloane, Sep 16 2000

Keywords

Comments

It appears that if s(n) is a first-order rational sequence of the form s(0)=4, s(n) = (2*s(n-1)+1)/(s(n-1)+2), n > 0, then s(n) = a(n)/(a(n)-1), n > 0.

Examples

			G.f. = 3*x + 8*x^2 + 23*x^3 + 68*x^4 + 203*x^5 + 608*x^6 + 1823*x^7 + 5468*x^8 + ...
		

Crossrefs

Related to A046901.
Equals A060816 + 1.
Cf. A135423 (bisection), A191450 (2nd row).

Programs

Formula

a(n+1) = 3*a(n) - 1 for n > 1. - Reinhard Zumkeller, Jan 22 2011
G.f.: (5/2)*U(0) where U(k) = 1 + 2/(5*3^k + 5*3^k/(1 - 30*x*3^k/(15*x*3^k - 1/U(k+1)))); (continued fraction, 4-step). - Sergei N. Gladkovskii, Nov 01 2012
E.g.f.: (5/2)*U(0) where U(k) = 1 + 2/(5*3^k + 5*3^k/(1 - 30*x*3^k/(15*x*3^k - (k+1)/U(k+1)))); (continued fraction, 4-step). - Sergei N. Gladkovskii, Nov 01 2012
G.f.: x*(3-4*x) / ( (3*x-1)*(x-1) ). - R. J. Mathar, Jan 25 2015
E.g.f.: (5*exp(3*x) + 3*exp(x) - 8)/6. - Stefano Spezia, Aug 28 2023

Extensions

Incorrect zeroth term removed by Jon Perry, Oct 11 2012

A064389 Variation (4) 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 we try to add n: a(n) = a(n-1) + n if not already in the sequence; if this fails we try to subtract n+1 from a(n-1), or to add n+1 to a(n-1), or to subtract n+2, or to add n+2, etc., until one of these produces a positive number not already in the sequence - this is a(n).

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

This is the nicest of these variations. Is this a permutation of the natural numbers?
The number of steps before n appears is the inverse series, A078758. The height of n is in A126712.
See A078758 for the inverse permutation (in case this is a permutation of the positive integers). - M. F. Hasler, Nov 03 2014
After 10^12 terms, the smallest number which has not appeared is 5191516. - Benjamin Chaffin, Oct 09 2016

References

  • Suggested by J. C. Lagarias.

Crossrefs

Cf. A005132, A046901, A064387, A064388. Agrees with A064387 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 for i from 0 to 100 do t1 := a[nx-1]-nx-i; if t1>0 and h[t1] <> 1 then a[nx] := t1; if t1 < maxt then h[t1] := 1; fi; break; fi; 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; od; evalm(a);
  • Mathematica
    h[1] = 1; h[] = 0; maxt = 100000; a[1] = 1; a[] = 0; For[nx = 2, nx <= 1000, nx++, For[i = 0, i <= 100, i++, t1 = a[nx - 1] - nx - i; If[t1 > 0 && h[t1] != 1, a[nx] = t1; If[t1 < maxt, h[t1] = 1]; Break[]]; t1 = a[nx - 1] + nx + i; If[h[t1] != 1, a[nx] = t1; If[t1 < maxt, h[t1] = 1]; Break[]]]]; Table[a[n], {n, 1, 100}](* Jean-François Alcover, May 09 2012, after Maple *)
  • PARI
    A064389(n=1000,show=0)={ my(k,s,t); for(n=1,n, k=n; while( !(t>k && !bittest(s, t-k) && t-=k) && !(!bittest(s, t+k)  && t+=k), k++); s=bitor(s,1<M. F. Hasler, Nov 03 2014

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

A076039 Start with 1. Multiply or divide by n accordingly as a(n-1) is smaller or greater than n and then take the integer value (this is to ensure that a(n) > 0 for all n).

Original entry on oeis.org

1, 2, 6, 1, 5, 30, 4, 32, 3, 30, 2, 24, 1, 14, 210, 13, 221, 12, 228, 11, 231, 10, 230, 9, 225, 8, 216, 7, 203, 6, 186, 5, 165, 4, 140, 3, 111, 2, 78, 1, 41, 1722, 40, 1760, 39, 1794, 38, 1824, 37, 1850, 36, 1872, 35, 1890, 34, 1904, 33, 1914, 32, 1920, 31, 1922, 30, 1920
Offset: 1

Views

Author

Amarnath Murthy, Oct 29 2002

Keywords

Examples

			a(13) = 1 so a(14) = 14*1 = 14;
14 < 15 so a(15) = 14*15 = 210;
210 > 16 so a(16) = floor(210/16) = 13.
		

Crossrefs

Programs

  • Haskell
    a076039 n = a076039_list !! (n-1)
    a076039_list = f 1 1 where
       f n x = x' : f (n+1) x' where
               x' = (if x < n then (*) else div) x n
    -- Reinhard Zumkeller, Aug 24 2011
  • Mathematica
    next[{a_,b_}]:=Module[{c=a+1},{c,If[bHarvey P. Dale, Oct 06 2011 *)

Formula

a(n) = n*a(n-1) if a(n-1) < n, floor(a(n-1)/n) otherwise.
a(A003462(k)) = 1. For A003462(k) < n <= A003462(k+1), if n-A003462(k) is odd, then a(n) = (3*A003462(k)+3-n)/2 and if n-A003462(k) is even, then a(n) = n*a(n-1). - David Wasserman, Mar 13 2005

Extensions

More terms from David Wasserman, Mar 13 2005

A085059 a(1) = 1, a(n+1) = a(n)-n if a(n) > n else a(n+1) = a(n) + n.

Original entry on oeis.org

1, 2, 4, 1, 5, 10, 4, 11, 3, 12, 2, 13, 1, 14, 28, 13, 29, 12, 30, 11, 31, 10, 32, 9, 33, 8, 34, 7, 35, 6, 36, 5, 37, 4, 38, 3, 39, 2, 40, 1, 41, 82, 40, 83, 39, 84, 38, 85, 37, 86, 36, 87, 35, 88, 34, 89, 33, 90, 32, 91, 31, 92, 30, 93, 29, 94, 28, 95, 27, 96, 26, 97, 25, 98, 24, 99
Offset: 1

Views

Author

Amarnath Murthy and Meenakshi Srikanth (menakan_s(AT)yahoo.com), Jun 27 2003

Keywords

Comments

Let (3^k-1)/2 = r then a((3^k-1)/2) = a(r) = 1 and a(r-1) = r. Geometrical interpretation. The sequence is obtained by the following rule: A point moves on the positive number line with the rule that in every step it has to move one unit more than the previous step and with the aim that it is to be as close to 0 as possible but on the positive side.

Crossrefs

Cf. A005132.
Equals 1+A008344(n).
Cf. A046901.

Programs

  • Haskell
    a085059 n = a085059_list !! (n-1)
    a085059_list = 1 : f 1 1 where
       f v w = y : f (v + 1) y where
         y = if w > v then w - v else w + v
    -- Reinhard Zumkeller, Jan 31 2013
  • Mathematica
    RecurrenceTable[{a[1]==1,a[n+1]==If[a[n]>n,a[n]-n , a[n]+n]}, a[n], {n,80}] (* Harvey P. Dale, May 11 2011 *)

Formula

a(A003462(n)) = 1. - Reinhard Zumkeller, Jan 31 2013

Extensions

More terms from Sam Alexander, Oct 20 2003
Showing 1-10 of 15 results. Next