-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdayJ.py
45 lines (38 loc) · 952 Bytes
/
dayJ.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
#!/usr/bin/env python3
import string
myfile = open('input.txt', 'r')
contents = myfile.read().splitlines()
myfile.close()
letters = []
# start at the entrance
row = 0
col = contents[row].find('|')
bearing = 'S' # start by traveling south
curr = contents[row][col]
count = 0
while curr != ' ':
if bearing == 'N':
row -= 1
elif bearing == 'E':
col += 1
elif bearing == 'S':
row += 1
elif bearing == 'W':
col -= 1
curr = contents[row][col]
if curr == '+':
if bearing in ('N', 'S'):
if contents[row][col + 1] == '-':
bearing = 'E'
else:
bearing = 'W'
else:
if contents[row - 1][col] == '|':
bearing = 'N'
else:
bearing = 'S'
elif curr not in ('|', '-'):
letters.append(curr)
count += 1
print("Part One:", ''.join(letters))
print("Part Two:", count)