|
|
A274369
|
|
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
|
|
|
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, 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, -2, -2, -1, -1, -2, -2, -3, -3, -2, -2, -1, -1, -2, -2, -3
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
0,21
|
|
LINKS
|
|
|
FORMULA
|
|
|
PROG
|
(Python)
def ant(n):
steps = [(1, 0), (0, 1), (-1, 0), (0, -1)]
black = set()
x = y = 0
position = [(x, y)]
direction = 2
for _ in range(n):
if (x, y) in black:
black.remove((x, y))
direction += 1
else:
black.add((x, y))
direction -= 1
(dx, dy) = steps[direction%4]
x += dx
y += dy
position.append((x, y))
return position
print([p[0] for p in ant(100)])
# change p[0] to p[1] to get y-coordinates
|
|
CROSSREFS
|
|
|
KEYWORD
|
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|