Files
python-aoc-2021/day05/part1.py
Sebastian Seedorf 7a154ed958 Day 05 (glamorized)
2021-12-13 10:36:41 +01:00

17 lines
522 B
Python

#!/usr/bin/env python3
import re
lines = (x.strip() for x in open("input.txt"))
points = {}
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):
points[(x1, y)] = points.get((x1, y), 0) + 1
elif y1 == y2:
for x in range(min(x1, x2), max(x1, x2)+1):
points[(x, y1)] = points.get((x, y1), 0) + 1
print(sum(1 if val >= 2 else 0 for val in points.values()))