27 lines
582 B
Python
27 lines
582 B
Python
#!/usr/bin/env python3
|
|
|
|
lines = (x.strip() for x in open("input.txt"))
|
|
|
|
blacks = set()
|
|
|
|
for line in lines:
|
|
x, y = 0, 0
|
|
while len(line):
|
|
if line[0] == "n":
|
|
y += 1
|
|
x += 1 if line[1] == "e" else 0
|
|
line = line[2:]
|
|
elif line[0] == "s":
|
|
y -= 1
|
|
x -= 1 if line[1] == "w" else 0
|
|
line = line[2:]
|
|
else:
|
|
x += 1 if line[0] == "e" else -1
|
|
line = line[1:]
|
|
if (x, y) in blacks:
|
|
blacks.discard((x, y))
|
|
else:
|
|
blacks.add((x, y))
|
|
|
|
print(len(blacks))
|