Search: id:A005132
Results 1-1 of 1 results found.
%I A005132 M2511
%S A005132 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,
%T A005132 43,16,44,15,45,14,46,79,113,78,114,77,39,78,38,79,37,80,36,81,35,82,34,
%U A005132 83,33,84,32,85,31,86,30,87,29,88,28,89,27,90,26,91,157,224,156,225,155
%N A005132 Recaman's sequence: a(0) = 0; for n > 0, a(n) = a(n-1)-n if that number
is positive and not already in the sequence, otherwise a(n) = a(n-1)+n.
%C A005132 The name "Recaman's sequence" is due to N. J. A. Sloane (njas(AT)research.att.com),
not the author!
%C A005132 I conjecture that every number eventually appears - see A057167, A064227,
A064228. - N. J. A. Sloane (njas(AT)research.att.com).
%C A005132 Comment from David Wilson (dwilson(AT)gambitcomm.com), 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.
%C A005132 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.
%C A005132 Clearly, there are injections satisfying [1] and [2], e.g, a(n) = n(n+1)/
2.
%C A005132 Is there a lexicographically smallest injection satisfying [1] and [2]?
(End)
%D A005132 N. J. A. Sloane and Simon Plouffe, The Encyclopedia of Integer Sequences,
Academic Press, 1995 (includes this sequence).
%D A005132 N. J. A. Sloane and A. R. Wilks, On sequences of Recaman type, paper
in preparation, 2006.
%H A005132 N. J. A. Sloane, The first 100000 terms
%H A005132 GBnums, See: A
nice OEIS sequence
%H A005132 Nick Hobson, Python program for this sequence
a>
%H A005132 C. L. Mallows, Plot (jpeg) of first 10000 terms
a>
%H A005132 C. L. Mallows, Plot (postscript) of first 10000 terms
a>
%H A005132 N. J. A. Sloane,
My favorite integer sequences, in Sequences and their Applications
(Proceedings of SETA '98).
%H A005132 N. J. A. Sloane, FORTRAN program for A005132, A057167,
A064227, A064228
%H A005132 Index entries for sequences related
to Recaman's sequence
%e A005132 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.
%p A005132 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
%t A005132 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
%t A005132 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] [From
Robert G. Wilson v (rgwv(AT)rgwv.com), May 01 2009]
%o A005132 (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)) (from Benoit Cloitre)
%o A005132 A005132( nMax=10^3 )={ local( s, t ); for( n=1,nMax, print1( t += if(
t<=n | bittest( s, t-n ), n, -n), ","); s=bitor( s, 1<