login
a(0) = 0; for n > 0, if a(n-1) - n >= 0 and a(n-1) - n has appeared the same or fewer times than a(n-1) + n, then a(n) = a(n-1) - n. Otherwise a(n) = a(n-1) + n.
2

%I #27 Jan 09 2022 02:31:01

%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,42,

%T 17,43,16,44,15,45,14,46,79,113,78,114,77,39,0,40,81,123,80,36,81,35,

%U 82,34,83,33,84,32,85,31,86,30,87,29,88,28,89,27,90,26,91,157,224,156,225,155,226,154,227

%N a(0) = 0; for n > 0, if a(n-1) - n >= 0 and a(n-1) - n has appeared the same or fewer times than a(n-1) + n, then a(n) = a(n-1) - n. Otherwise a(n) = a(n-1) + n.

%C This sequence is similar to the Recamán sequence A005132 except that here the number chosen to step to, if a(n-1) - n is >= 0, is determined by which of the two possible numbers, a(n-1) - n or a(n-1) + n, has appeared the fewest times. If the number of times these numbers have appeared is the same then a(n) = a(n-1) - n. If a(n-1) - n is less than zero then a(n) = a(n-1) + n.

%C The first term to differ from A005132 is a(39) = 0. See the examples below. In the first 10^8 terms the largest value is a(99928118) = 842174195, while the smallest number not to have appeared is 366. It is likely all numbers eventually appear although this is unknown.

%C See the companion sequence A350579 for the first number to appear n times.

%H Scott R. Shannon, <a href="/A350578/a350578.png">Image of the first 10^8 terms</a>.

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

%e a(3) = 6 as a(2) = 3 giving the two possible numbers for the next step as 0 or 6. But 0 has already appeared once while 6 has not yet appeared, so 6 is chosen.

%e a(39) = 0 as a(38) = 39 giving the two possible numbers for the next step as 0 or 78. Both 0 and 78 have already appeared once thus the smaller is chosen. This is the first term to differ from A005132.

%e a(447) = 934 as a(446) = 487 giving the two possible numbers for the next step as 40 or 934. 40 has already appeared twice while 934 has appeared once, so the later is chosen. This is the first time both possible numbers have already appeared and the larger is chosen.

%e a(2462) = 551 as a(2461) = 3013 giving the two possible numbers for the next step as 551 or 5475. 551 has already appeared once while 5475 has appeared twice, so the former is chosen. This is the first time both possible numbers have already appeared and the smaller is chosen.

%t a[0]=0;a[n_]:=a[n]=If[a[n-1]-n>=0&&Count[Array[a,n-1,0],a[n-1]-n]<=Count[Array[a,n-1,0],a[n-1]+n],a[n-1]-n,a[n-1]+n];Array[a,74,0] (* _Giorgos Kalogeropoulos_, Jan 07 2022 *)

%o (Python)

%o from itertools import count, islice

%o from collections import Counter

%o def A350578_gen(): # generator of terms

%o yield 0

%o b, bcounter = 0, Counter({0})

%o for n in count(1):

%o b += -n if b-n >= 0 and bcounter[b-n] <= bcounter[b+n] else n

%o bcounter[b] += 1

%o yield b

%o A350578_list = list(islice(A350578_gen(),30)) # _Chai Wah Wu_, Jan 08 2022

%Y Cf. A005132, A350579, A335299, A064389, A261573, A064387.

%K nonn

%O 0,3

%A _Scott R. Shannon_, Jan 07 2022