Day 24
This commit is contained in:
26
day24/part1.py
Normal file
26
day24/part1.py
Normal file
@@ -0,0 +1,26 @@
|
||||
#!/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))
|
||||
Reference in New Issue
Block a user