-
Notifications
You must be signed in to change notification settings - Fork 1
/
19a_aoc.py
63 lines (58 loc) · 1.32 KB
/
19a_aoc.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
54
55
56
57
58
59
60
61
62
63
inp = []
def main():
global inp
try:
while True:
inp.append(raw_input())
except EOFError:
solve(inp)
def up(arg):
x,y = arg
return (x,y-1)
def left(arg):
x,y = arg
return (x-1,y)
def right(arg):
x,y = arg
return (x+1,y)
def down(arg):
x,y = arg
return (x,y+1)
def get(sp):
x,y = sp
return inp[y][x]
def solve(arg):
#find starting pt
sp = (0,0)
going = down
symbol = "|"
letters = ""
for x in range(len(inp[0])):
if inp[0][x] == "|":
sp = (x,0)
while symbol != ' ':
#print sp,get(sp)
sp = going(sp)
symbol = get(sp)
if symbol == "+":
# change direction
if going == up:
coming_from = down
if going == down:
coming_from = up
if going == left:
coming_from = right
if going == right:
coming_from = left
dirs = [up,down,left,right]
for dirc in dirs:
try:
if get(dirc(sp))!=" ":
if coming_from != dirc:
going = dirc
except IndexError:
pass
if 'A'<=symbol<='Z':
letters += symbol
print letters
main()