-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day5.py
59 lines (40 loc) · 1.26 KB
/
Day5.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
path = "./Inputs/day5.txt"
# path = "./Inputs/day5Test.txt"
def part1():
seats = getSeats()
highestSeat = max(seats)
print("Part 1:")
print(highestSeat)
def part2():
seats = getSeats()
# get the missing seat
difference = sorted(set(range(seats[0], seats[-1] + 1)).difference(seats))
print("Part 2:")
print(difference[0])
def getSeats():
seats = []
with open(path) as file:
for line in file.readlines():
rows = list(range(128))
cols = list(range(8))
letters = list(line.rstrip('\n'))
for letter in letters:
if(letter == 'F' or letter == 'B'):
rows = splitList(rows, letter)
elif(letter == 'L' or letter == 'R'):
cols = splitList(cols, letter)
row = rows[0]
col = cols[0]
seat = row * 8 + col
seats.append(seat)
return seats
def splitList(origList, part):
if (part == 'F' or part == 'L'):
# take first half
new_list = origList[:len(origList)//2]
else:
# take second half
new_list = origList[len(origList)//2:]
return new_list
part1()
part2()