login
Let the starting square of Langton's ant have coordinates (0, 0), with the ant looking in negative x-direction. a(n) is the x-coordinate of the ant after n moves.
5

%I #27 May 15 2021 05:45:20

%S 0,0,1,1,0,0,-1,-1,0,0,1,1,0,0,1,1,0,0,1,1,2,2,1,1,2,2,3,3,2,2,1,1,2,

%T 2,3,3,4,4,3,3,2,2,3,3,2,2,3,3,2,2,1,1,0,0,-1,-1,0,0,-1,-1,0,0,-1,-1,

%U -2,-2,-1,-1,-2,-2,-3,-3,-2,-2,-1,-1,-2,-2,-3

%N Let the starting square of Langton's ant have coordinates (0, 0), with the ant looking in negative x-direction. a(n) is the x-coordinate of the ant after n moves.

%H Rémy Sigrist, <a href="/A274369/b274369.txt">Table of n, a(n) for n = 0..15000</a>

%H Felix Fröhlich, <a href="/A274369/a274369.pdf">Coordinates of Langton's ant</a>.

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Langton%27s_ant">Langton's ant</a>.

%F a(n+104) = a(n) + 2 for n > 9975. - _Andrey Zabolotskiy_, Jul 05 2016

%o (Python)

%o # A274369: Langton's ant by _Andrey Zabolotskiy_, Jul 05 2016

%o def ant(n):

%o steps = [(1, 0), (0, 1), (-1, 0), (0, -1)]

%o black = set()

%o x = y = 0

%o position = [(x, y)]

%o direction = 2

%o for _ in range(n):

%o if (x, y) in black:

%o black.remove((x, y))

%o direction += 1

%o else:

%o black.add((x, y))

%o direction -= 1

%o (dx, dy) = steps[direction%4]

%o x += dx

%o y += dy

%o position.append((x, y))

%o return position

%o print([p[0] for p in ant(100)])

%o # change p[0] to p[1] to get y-coordinates

%Y Cf. A274370 (y-coordinate).

%Y Cf. A102358, A102369, A204810, A255938, A261990, A269757.

%K sign,look

%O 0,21

%A _Felix Fröhlich_, Jun 19 2016