login
Starting at n, a(n) is the sign of the closest nonzero position to zero visited according to the following rules. On the k-th step (k=1,2,3,...) move a distance of k in the direction of zero. If the number landed on has been landed on before, move a distance of k away. In the cases of a tie or n=0, we set a(n)=0.
0

%I #9 Mar 12 2019 09:19:58

%S 0,1,0,1,1,0,1,0,0,0,1,1,1,0,-1,1,1,0,0,1,0,1,0,1,1,0,-1,0,1,1,0,-1,0,

%T 1,0,-1,1,1,0,-1,-1,-1,-1,1,0,1,0,0,0,-1,1,0,-1,-1,0,1,0,-1,1,0,1,1,1,

%U 0,-1,-1,1,1,1,0,-1,-1,-1,-1,0,-1,1,0,1,0

%N Starting at n, a(n) is the sign of the closest nonzero position to zero visited according to the following rules. On the k-th step (k=1,2,3,...) move a distance of k in the direction of zero. If the number landed on has been landed on before, move a distance of k away. In the cases of a tie or n=0, we set a(n)=0.

%e For n=14, the points visited are 14, 13, 11, 8, 4, -1, 5, -2, 6, -3, 7, -4, -16, -29, -15, 0. The closest of these to zero is -1, which is negative, thus a(14) = sgn(-1) = -1.

%o (Python)

%o #Sequences A324660-A324692 generated by manipulating this trip function

%o #spots - positions in order with possible repetition

%o #flee - positions from which we move away from zero with possible repetition

%o #stuck - positions from which we move to a spot already visited with possible repetition

%o def trip(n):

%o stucklist = list()

%o spotsvisited = [n]

%o leavingspots = list()

%o turn = 0

%o forbidden = {n}

%o while n != 0:

%o turn += 1

%o sign = n // abs(n)

%o st = sign * turn

%o if n - st not in forbidden:

%o n = n - st

%o else:

%o leavingspots.append(n)

%o if n + st in forbidden:

%o stucklist.append(n)

%o n = n + st

%o spotsvisited.append(n)

%o forbidden.add(n)

%o return {'stuck':stucklist, 'spots':spotsvisited,

%o 'turns':turn, 'flee':leavingspots}

%o def sgn(x):

%o if x:

%o return x//abs(x)

%o return 0

%o def maxorzero(x):

%o if x:

%o return max(x)

%o return 0

%o def minorzero(x):

%o if x:

%o return min(x)

%o return 0

%o #Actual sequence

%o def a(n):

%o d = trip(n)

%o neg=maxorzero([i for i in d['spots'] if i < 0])

%o pos=minorzero([i for i in d['spots'] if i > 0])

%o return (-sgn(neg+pos) + [2,0][sgn(neg)])*sgn(n)

%Y Cf. A228474, A324660-A324692.

%K sign

%O 0

%A _David Nacin_, Mar 10 2019