login
A variation on Recamán's sequence (A005132): a(0) = 0, a(n) = a(n-1) - n if nonnegative and not already in the sequence; otherwise, a(n) = a(n-1) + ceiling(n/2) if not already in the sequence and a(n) = a(n-1) + n if already in the sequence.
2

%I #33 Sep 16 2022 02:14:48

%S 0,1,2,4,6,9,3,7,11,16,21,10,22,29,15,23,31,14,32,13,33,12,34,46,58,

%T 71,45,18,46,17,47,63,79,96,62,27,63,26,64,25,65,24,66,88,44,67,90,43,

%U 91,42,92,41,93,40,94,39,95,38,96,37,97,36,98,35,99,132,165

%N A variation on Recamán's sequence (A005132): a(0) = 0, a(n) = a(n-1) - n if nonnegative and not already in the sequence; otherwise, a(n) = a(n-1) + ceiling(n/2) if not already in the sequence and a(n) = a(n-1) + n if already in the sequence.

%C In this sequence, a forward step of ceiling(n/2) is added if a(n) - n is negative and a(n-1) + ceiling(n/2) is not already in the sequence. As a result, both the number of distinct numbers and the number of distinct numbers as a percentage of the biggest number in the sequence (called "coverage") are increased.

%C The smallest missing numbers, h1, from the first m terms of the sequence, given as h1(m), are: 3(6), 5(11097), 57(49518), 149(92113), 159(124908), ... All integers less than or equal to h1 can be found in the first m+1 terms of the sequence.

%C The number of consecutive numbers (Nc, from 0 to Nc-1), the distinct numbers (Nd), the biggest number (a_max), and the "coverage" for n=0~1000000 in the sequences with different forward and backward steps are given below:

%C Sequence Backward Forward Nc Nd a_max coverage

%C A005132 -n +n 1355 736749 5946126 12.39%

%C A335923 -n +n/2 620 694811 4350902 15.97%

%C "B" -n +n/4 577 696167 3132344 22.23%

%C A335924 -n +n/2, +n 160 813204 5698099 14.27%

%C "C" -n +n/4, +n/2 1330 779087 3757167 20.74%

%C "D" -2n, -n +n/2, +n 24 901949 3639015 24.79%

%C "E" -2n, -n +n/4, +n/2 3414 817174 3128675 26.12%

%H Michael De Vlieger, <a href="/A335924/b335924.txt">Table of n, a(n) for n = 0..10000</a>

%H Altug Alkan, Andrew R. Booker, and Florian Luca, <a href="https://arxiv.org/abs/2006.08013">On a recursively defined sequence involving the prime counting function</a>, arXiv:2006.08013 [math.NT], 2020.

%t Nest[Append[#1, If[And[#3 >= 0, FreeQ[#1, #3]], #3, If[FreeQ[#1, #4], #4, #1[[-1]] + #2]]] & @@ {#1, #2, #1[[-1]] - #2, #1[[-1]] + Ceiling[#2/2]} & @@ {#, Length@ #} &, {0}, 10^5] (* _Michael De Vlieger_, Sep 09 2020 *)

%o (Python)

%o import math

%o n_max = 1000000

%o a_last = 0

%o list1 = [a_last]

%o print(0)

%o for n in range(1, n_max+1):

%o m1 = a_last - n

%o m2 = a_last + math.ceil(n/2)

%o if m1 >= 0 and m1 not in list1:

%o a = m1

%o elif m2 not in list1:

%o a = m2

%o else:

%o a = a_last + n

%o list1.append(a)

%o print(a)

%o a_last = a

%o (Python)

%o from itertools import count, islice

%o def A335924_gen(): # generator of terms

%o a, aset = 0, set()

%o for n in count(1):

%o yield a

%o aset.add(a)

%o a = b if (b:=a-n)>=0 and b not in aset else c if (c:=(n+1>>1)+a) not in aset else a+n

%o A335924_list = list(islice(A335924_gen(),70)) # _Chai Wah Wu_, Sep 15 2022

%Y Cf. A005132, A335923.

%K nonn

%O 0,3

%A _Ya-Ping Lu_, Jun 29 2020