This commit is contained in:
Sebastian Seedorf
2021-12-06 11:11:21 +01:00
parent 074e2b683f
commit aea44ca7aa
3 changed files with 545 additions and 0 deletions

19
day05/part1.py Normal file
View File

@@ -0,0 +1,19 @@
#!/usr/bin/env python3
import re
from collections import defaultdict
lines = (x.strip() for x in open("input.txt"))
points = defaultdict(int)
for line in lines:
[x1, y1, x2, y2] = list(map(int, re.match(r"(\d+),(\d+) -> (\d+),(\d+)", line).groups()))
if x1 == x2:
for y in range(min(y1, y2), max(y1, y2)+1):
key = '{},{}'.format(x1, y)
points[key] = points[key] + 1
elif y1 == y2:
for x in range(min(x1, x2), max(x1, x2)+1):
key = '{},{}'.format(x, y1)
points[key] = points[key] + 1
print(sum(1 if val >= 2 else 0 for val in points.values()))