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.
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
Keywords
Examples
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.
Links
Programs
-
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 *)
-
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
Comments