-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday19.py
More file actions
45 lines (39 loc) · 882 Bytes
/
day19.py
File metadata and controls
45 lines (39 loc) · 882 Bytes
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
45
#AoC Day 19 -- A series of tubes
#This problem was pretty conceptually challenging, so I broke it into a lot of
#subproblems
opened = open("day19.txt", 'r').read()
lines = opened.splitlines()
x = 0
y = 0
d = 0
out = ""
count = 0
while lines[y][x] == " ":
x += 1
while True:
if lines[y][x] == " ":
break # Sorry
count += 1
if lines[y][x] == "+":
if d in [0, 2]:
if x > 0 and lines[y][x-1] is not " ":
d = 3
elif x < len(lines[y])-1 and lines[y][x+1] is not " ":
d = 1
else:
if y > 0 and lines[y-1][x] is not " ":
d = 2
elif y < len(lines)-1 and lines[y+1][x] is not " ":
d = 0
elif lines[y][x].isalpha():
out += lines[y][x]
if d == 0:
y += 1
elif d == 1:
x += 1
elif d == 2:
y -= 1
elif d == 3:
x -= 1
print(out)
print(count)