AoC/2015/days/03/walk.py

35 lines
508 B
Python

#!/usr/bin/env python3
count = 0
x = 0
y = 0
visited = {}
MOTION = {
"^": [0, -1],
"<": [-1, 0],
"v": [0, 1],
">": [1, 0]
}
def move(char):
global x
global y
motion = MOTION[char]
x += motion[0]
y += motion[1]
visit(x, y)
def visit(x, y):
global count
if (x, y) not in visited:
visited[(x, y)] = 1
count += 1
visit(x, y)
with open("./data/input", "r") as f:
for line in f:
for char in line:
move(char)
print(count)