-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.py
48 lines (41 loc) · 1.11 KB
/
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
42
43
44
45
46
47
48
input = open("data.txt","r").read().split("\n")
x,y = input[0].index("|"), 0
d = "s"
NoWayToGo = False
letters = []
steps = 0
while not NoWayToGo:
while True:
if input[y][x] not in ["|", "-", "+"]: letters.append(input[y][x])
if d=="n": y -= 1
if d=="s": y += 1
if d=="w": x -= 1
if d=="e": x += 1
if x<0 or x>=input[0].__len__() or y<0 or y>=input.__len__():
NoWayToGo = True
break
steps += 1
if input[y][x] == "+": break
if d=="n" or d=="s":
if x>0:
if input[y][x-1]=="-":
d = "w"
continue
if x<input[0].__len__()-1:
if input[y][x+1]=="-":
d = "e"
continue
if d=="e" or d=="w":
if y>0:
if input[y-1][x]=="|":
d = "n"
continue
if y<input.__len__()-1:
if input[y+1][x]=="|":
d = "s"
continue
NoWayToGo = True
# First part
print("First part: " + "".join(letters))
# Second part
print("Second part: " + str(steps))