login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A324682 Starting at n, a(n) is the sign of the closest nonzero point to zero visited for which the next move is a step away from zero, 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 case of a tie, or if the set of points is empty, we set a(n)=0. 0

%I #14 Jan 10 2023 10:55:04

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

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

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

%N Starting at n, a(n) is the sign of the closest nonzero point to zero visited for which the next move is a step away from zero, 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 case of a tie, or if the set of points is empty, we set a(n)=0.

%e For n=9, the points visited are 9, 8, 6, 3, -1, 4, -2, 5, -3, -12, -22, -11, 1, 14, 0. The three times moves are made away from zero happen at -3, -12 and 1. The closest of these is to zero is 1 and thus a(9) = 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['flee'] if i < 0])

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

%o if neg and not pos:

%o return -1

%o return -sgn(neg+pos)

%Y Cf. A228474, A324660-A324692.

%K sign

%O 0,1

%A _David Nacin_, Mar 10 2019

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 23 16:40 EDT 2024. Contains 371916 sequences. (Running on oeis4.)