]> git.friedersdorff.com Git - max/advent_of_code_2021.git/blob - 5_1.py
Try day 14
[max/advent_of_code_2021.git] / 5_1.py
1 """Find the dangerous vents"""
2 import numpy as np
3
4 vent_field = np.zeros((1000, 1000))
5
6 with open("5_input.txt") as f:
7     for line in f:
8         p1, p2 = line.split("->")
9         x1, y1, x2, y2 = [int(x) for x in p1.split(",") + p2.split(",")]
10
11         if x1 == x2:
12             for y in range(min(y1, y2), max(y1, y2) + 1):
13                 vent_field[x1][y] += 1
14         elif y1 == y2:
15             for x in range(min(x1, x2), max(x1, x2) + 1):
16                 vent_field[x][y1] += 1
17
18 print(len(np.argwhere(vent_field > 1)))