# [seqfan] Re: Subtracting or adding n to a(n-1)

Joshua Zucker joshua.zucker at gmail.com
Wed Apr 29 20:15:24 CEST 2009

```On Wed, Apr 29, 2009 at 9:31 AM, Leroy Quet <q1qq2qqq3qqqq at yahoo.com> wrote:
> Consider the sequence:
> a(0)=0.
> a(n) = |a(n-1)-n|, if |a(n-1)-n| does not occur among terms a(0) through a(n-1).
> a(n) = a(n-1)+n, otherwise.
>
> This starts the same as Recaman's sequence, A005132.
> a(0)=0. a(n) = a(n-1)-n if a(n-1)-n is positive and does not occur earlier in the sequence.
> a(n) = a(n-1)+n, otherwise.
>
> Are they the same sequence?

No.  At 57, Recaman goes 30 + 57 = 87, while your sequence goes |30 - 57| = 27.
Here are the first few hundred terms of your sequence:
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 27 85 26 86 147 209 146 210 145 211 144 76 145
75 4 68 5 69 144 220 143 65 144 64 145 227 310 226 141 55 142 54 143
53 144 52 145 51 146 50 47 145 244 344 243 345 242 138 243 137 244 136
245 135 246 134 247 133 248 132 249 131 250

And here's the Scheme program I used to generate them:
(define (recaman lon n)
(cond
[(= n 1000) (reverse lon)]
[else (let ([next (abs (- (first lon) n))])
(if (ormap (lambda (a) (= a next)) lon)
(recaman (cons (+ n (first lon)) lon) (add1 n))
(recaman (cons next lon) (add1 n))))]))
(recaman (list 0) 1)

>
> Next question: Consider my sequence again, but let a(0) = the integer m.
>
> We can construct 3 sequences here, where {a_m(k)} is my sequence with starting value m:
>
> b(m) = the smallest positive integer j such that a_m(j) = a_m(k) for some k where 0<=k<j.
>
> I think this sequence begins (offset 0):
> 24,16,21,3,12,..
> (Not in EIS.)

I don't understand this.  Isn't it true that by definition a_m(j)
never equals a_m(k)?  I'm sure I'm missing something, and when you
explain it I'm happy to write a program to generate more terms of
these if that would be useful.

--Joshua Zucker

```