login
A387683
a(0) = 0; thereafter a(n) = a(n-1) - n if a(n-1) >= 2*n and not already in the sequence, otherwise a(n) = a(n-1) + n.
1
0, 1, 3, 6, 10, 5, 11, 18, 26, 17, 27, 16, 28, 15, 29, 44, 60, 43, 25, 44, 24, 45, 23, 46, 70, 95, 69, 42, 70, 41, 71, 40, 72, 39, 73, 38, 74, 37, 75, 114, 154, 113, 155, 112, 68, 113, 67, 114, 66, 115, 65, 116, 64, 117, 63, 118, 62, 119, 61, 120, 180
OFFSET
0,3
LINKS
EXAMPLE
a(4) = 10 because subtracting 4 from the previous term (6) would give 2, which is smaller than 4, so add 4 to 6 to get 10.
a(5) = 5 because subtracting 5 from the previous term (10) gives 5, which is equal to a(n), and has not appeared before.
a(8) = 18 because subtracting 8 from the previous term (18) gives 10, which has appeared before, so add 8 to 18 to get 26.
MATHEMATICA
s={0}; Do[If[s[[-1]]>=2n&&!MemberQ[s, s[[-1]]-n], AppendTo[s, s[[-1]]-n], AppendTo[s, s[[-1]]+n]], {n, 60}]; s (* James C. McMahon, Sep 15 2025 *)
CROSSREFS
Sequence in context: A232175 A396346 A065234 * A333531 A082184 A080817
KEYWORD
nonn
AUTHOR
Kelvin Voskuijl, Sep 05 2025
STATUS
approved