OFFSET
0,8
EXAMPLE
For n=41, the points visited are 41, 40, 38, 35, 31, 26, 20, 13, 5, -4, 6, -5, 7, -6, 8, -7, 9, -8, 10, -9, 11, -10, 12, -11, -35, -60, -34, -61, -33, -62, -32, -1, -33, 0. The only position from which we are forced to revisit a spot is -1 which forces a return to -33. As this is the only position and it is negative, it is the minimum negative position and thus a(41)=-1.
PROG
(Python)
#spots - positions in order with possible repetition
#flee - positions from which we move away from zero with possible repetition
#stuck - positions from which we move to a spot already visited with possible repetition
def trip(n):
stucklist = list()
spotsvisited = [n]
leavingspots = list()
turn = 0
forbidden = {n}
while n != 0:
turn += 1
sign = n // abs(n)
st = sign * turn
if n - st not in forbidden:
n = n - st
else:
leavingspots.append(n)
if n + st in forbidden:
stucklist.append(n)
n = n + st
spotsvisited.append(n)
forbidden.add(n)
return {'stuck':stucklist, 'spots':spotsvisited,
'turns':turn, 'flee':leavingspots}
def minorzero(x):
if x:
return min(x)
return 0
#Actual sequence
def a(n):
d=trip(n)
return minorzero([i for i in d['stuck'] if i<0])
CROSSREFS
KEYWORD
sign
AUTHOR
David Nacin, Mar 10 2019
STATUS
approved