login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A274647 A variation 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 2n from a(n-1), or to add 2n to a(n-1), or to subtract 3n, or to add 3n, etc., until one of these produces a positive number not already in the sequence. 5

%I #55 May 06 2021 09:45:15

%S 0,1,3,6,2,7,13,20,12,21,11,22,10,23,9,24,8,25,43,62,42,63,41,18,66,

%T 91,65,38,94,123,93,124,92,59,127,162,126,89,51,90,50,132,174,131,87,

%U 177,223,176,128,79,29,80,28,81,27,82,26,83,141,200,140,201,139

%N A variation 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 2n from a(n-1), or to add 2n to a(n-1), or to subtract 3n, or to add 3n, etc., until one of these produces a positive number not already in the sequence.

%C Is this a permutation of the natural numbers?

%C After 5.4*10^11 terms, the smallest number which has not appeared is 212. There are 177 numbers under 10000 which have not appeared. - _Benjamin Chaffin_, Sep 29 2016

%H Antti Karttunen, <a href="/A274647/b274647.txt">Table of n, a(n) for n = 0..85000</a>

%H <a href="/index/Rea#Recaman">Index entries for sequences related to Recamán's sequence</a>

%F A276342(a(n)) = n for all n.

%t f[s_List] := Block[{a = b = 0, k = 1, l = s[[-1]], n = Length@ s}, While[ If[l > k*n && !MemberQ[s, l - k*n], a = l - k*n]; If[ !MemberQ[s, l + k*n], b = l + k*n; Break[]]; a == b == 0, k++]; Append[s, If[a > 0, a, b]]]; Nest[f, {0}, 70]

%t (* _Robert G. Wilson v_, Sep 09 2016 *)

%o (Scheme, with defineperm1-macro from Antti Karttunen's IntSeq-library)

%o (defineperm1 (A274647 n) (if (<= n 1) n (let ((prev (A274647 (- n 1)))) (let loop ((k n)) (cond ((and (> (- prev k) 1) (not-lte? (A276342 (- prev k)) n)) (- prev k)) ((not-lte? (A276342 (+ prev k)) n) (+ prev k)) (else (loop (+ k n))))))))

%o (define (A276342 n) (A274647 (- n))) ;; This returns inverse values of A274647 from its hidden cache.

%o ;; We consider a > b (i.e. not less than b) also in case a is #f.

%o ;; (Because of the stateful caching system used by defineperm1-macro):

%o (define (not-lte? a b) (cond ((not (number? a)) #t) (else (> a b))))

%o ;; _Antti Karttunen_, Sep 04 2016

%o (Python)

%o l=[0]

%o for n in range(1, 101):

%o i=1

%o while True:

%o a=l[n - 1]

%o x=a - i*n

%o if x>0 and x not in l:

%o l.append(x)

%o break

%o y=a + i*n

%o if y>0 and not y in l:

%o l.append(y)

%o break

%o else : i+=1

%o print(l) # _Indranil Ghosh_, Jun 03 2017

%Y Cf. A005132, A064389.

%Y Left inverse: A276342 (also right inverse, if this sequence is a permutation of nonnegative integers).

%Y Cf. A276438 (gives k that was used when computing a(n), with sign).

%Y Cf. A274648 (another variant).

%K nonn,nice

%O 0,3

%A _Max Barrentine_, Aug 12 2016

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 16 00:41 EDT 2024. Contains 371696 sequences. (Running on oeis4.)