login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A350578
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
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, 0, 40, 81, 123, 80, 36, 81, 35, 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
OFFSET
0,3
COMMENTS
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.
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.
See the companion sequence A350579 for the first number to appear n times.
EXAMPLE
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.
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.
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.
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.
MATHEMATICA
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 *)
PROG
(Python)
from itertools import count, islice
from collections import Counter
def A350578_gen(): # generator of terms
yield 0
b, bcounter = 0, Counter({0})
for n in count(1):
b += -n if b-n >= 0 and bcounter[b-n] <= bcounter[b+n] else n
bcounter[b] += 1
yield b
A350578_list = list(islice(A350578_gen(), 30)) # Chai Wah Wu, Jan 08 2022
CROSSREFS
KEYWORD
nonn
AUTHOR
Scott R. Shannon, Jan 07 2022
STATUS
approved