-
Notifications
You must be signed in to change notification settings - Fork 1
/
part1.py
44 lines (35 loc) · 957 Bytes
/
part1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
with open("input.txt", "r") as f:
data = f.read()
grid = [["."] * 1000 for i in range(1000)]
depth = 0
for line in data.split("\n"):
pairs = [list(map(int, p.split(","))) for p in line.split("->")]
for p1, p2 in zip(pairs, pairs[1:]):
p1 = p1[:]
p2 = p2[:]
p1[0], p2[0] = sorted([p1[0], p2[0]])
p1[1], p2[1] = sorted([p1[1], p2[1]])
for r in range(p1[0], p2[0] + 1):
for c in range(p1[1], p2[1] + 1):
grid[r][c] = "#"
depth = max(depth, p2[1])
count = 0
while True:
x = 500
y = 0
while True:
if grid[x][y + 1] == ".":
y += 1
elif grid[x - 1][y + 1] == ".":
x -= 1
y += 1
elif grid[x + 1][y + 1] == ".":
x += 1
y += 1
else:
grid[x][y] = "o"
break
if y == depth + 1:
print(count)
exit()
count += 1