OFFSET
1,6
COMMENTS
Similar logic as van Eck's sequence except that if a(n) hasn't appeared before, then a(n+1) = -a(n) instead of being 0.
FORMULA
If a(n) < 0, then a(n+1) = -a(n) and a(n+2) = 2. - Rémy Sigrist, Jul 14 2019
EXAMPLE
We start with a(1) = 0.
0 has not occurred before, so our rule says that a(2) = -a(1) = 0.
Now 0 has occurred before, at a(1), which is 1 term before, so a(3) = 1.
1 has not occurred before, so a(4) = -a(3) = -1.
-1 has not occurred before, so a(5) = -a(4) = 1.
Now 1 has occurred before, at a(3), which is 2 term before, so a(6) = 2.
2 has not occurred before, so a(6) = -a(5) = -2.
And so on...
PROG
(Python)
import numpy as np
def A308619(n):
NegVanEck = np.array([0])
#first value is 0
i=NegVanEck[0]
while i < n:
last = NegVanEck[-1]
pos = np.where(NegVanEck == last)
if pos[0].size == 1:
NegVanEck = np.append(NegVanEck, -last)
else:
NegVanEck = np.append(NegVanEck, pos[0][-1] - pos[0][-2])
i += 1
return NegVanEck
print(A308619(1000)) #prints first 1000 integers of the sequence
CROSSREFS
KEYWORD
sign
AUTHOR
João D. R. Camacho, Jun 11 2019
STATUS
approved