A335924 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.
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, 71, 45, 18, 46, 17, 47, 63, 79, 96, 62, 27, 63, 26, 64, 25, 65, 24, 66, 88, 44, 67, 90, 43, 91, 42, 92, 41, 93, 40, 94, 39, 95, 38, 96, 37, 97, 36, 98, 35, 99, 132, 165
Offset: 0
Keywords
Links
- Michael De Vlieger, Table of n, a(n) for n = 0..10000
- Altug Alkan, Andrew R. Booker, and Florian Luca, On a recursively defined sequence involving the prime counting function, arXiv:2006.08013 [math.NT], 2020.
Programs
-
Mathematica
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 *)
-
Python
import math n_max = 1000000 a_last = 0 list1 = [a_last] print(0) for n in range(1, n_max+1): m1 = a_last - n m2 = a_last + math.ceil(n/2) if m1 >= 0 and m1 not in list1: a = m1 elif m2 not in list1: a = m2 else: a = a_last + n list1.append(a) print(a) a_last = a
-
Python
from itertools import count, islice def A335924_gen(): # generator of terms a, aset = 0, set() for n in count(1): yield a aset.add(a) 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 A335924_list = list(islice(A335924_gen(),70)) # Chai Wah Wu, Sep 15 2022
Comments