This commit is contained in:
Sebastian Seedorf
2020-12-30 16:40:28 +01:00
parent 1e78940455
commit 8cc845167e
3 changed files with 501 additions and 0 deletions

26
day24/part1.py Normal file
View 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))