-
Notifications
You must be signed in to change notification settings - Fork 0
/
19.py
53 lines (45 loc) · 1.01 KB
/
19.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
45
46
47
48
49
50
51
52
53
from lib import *
input = read_input(2017, 19)
lines = input.splitlines()
w, h = len(lines[0]), len(lines)
x, y = lines[0].index("|"), 0
dx, dy = 0, 1
out = ""
get = lambda x, y: lines[y][x] if y in range(h) and x in range(w) else " "
while True:
c = get(x, y)
f = get(x + dx, y + dy)
l = get(x + dy, y - dx)
r = get(x - dy, y + dx)
if c.isalpha():
out += c
if f == " ":
if l != " ":
dx, dy = dy, -dx
elif r != " ":
dx, dy = -dy, dx
else:
break
x += dx
y += dy
print(out)
w, h = len(lines[0]), len(lines)
x, y = lines[0].index("|"), 0
dx, dy = 0, 1
out = 0
get = lambda x, y: lines[y][x] if y in range(h) and x in range(w) else " "
while True:
out += 1
f = get(x + dx, y + dy)
l = get(x + dy, y - dx)
r = get(x - dy, y + dx)
if f == " ":
if l != " ":
dx, dy = dy, -dx
elif r != " ":
dx, dy = -dy, dx
else:
break
x += dx
y += dy
print(out)