-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_solution.py
41 lines (34 loc) · 936 Bytes
/
1_solution.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
import math
road = open('my.input').read().split('\n')
road = [list(x) for x in road]
letters = []
delta = 1
going_vertical = True
for idx,item in enumerate(road[0]):
if item == "|":
[x, y] = (0, idx)
break
while True:
if going_vertical:
x += delta
else:
y += delta
if road[x][y] == ' ':
print('Road ended at',x,y)
break
if road[x][y] == '+':
if going_vertical:
if road[x][y-1] == '-':
delta = -1
if road[x][y+1] == '-':
delta = 1
else:
if x-1 > 1 and road[x-1][y] == '|':
delta = -1
if x+1 < len(road) - 1 and road[x+1][y] == '|':
delta = 1
going_vertical = not going_vertical
continue
if road[x][y] != '|' and road[x][y] != '-':
letters.append(road[x][y])
print('Letters', ''.join(letters))