-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.py
More file actions
34 lines (29 loc) · 1.04 KB
/
day5.py
File metadata and controls
34 lines (29 loc) · 1.04 KB
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
def findSeatId(boardingPass):
rowBinary = boardingPass[0:7]
columnBinary = boardingPass[7:]
rowBinary = rowBinary.replace('F', '0').replace('B','1')
columnBinary = columnBinary.replace('L', '0').replace('R', '1')
row = int(rowBinary, 2)
column = int(columnBinary, 2)
return (8*row+column)
def findMissingPasses(seatIds, totalSeats):
missingSeats = []
for seat in range(totalSeats):
if seat not in seatIds:
missingSeats.append(seat)
return missingSeats
def findSantasSeat(missingSeats, seatIds):
for missingSeat in missingSeats:
if missingSeat-1 in seatIds and missingSeat+1 in seatIds:
return missingSeat
boardingPasses = [line.strip() for line in open('day5input.txt')]
max = 0
seatIds = []
for boardingPass in boardingPasses:
seatId = findSeatId(boardingPass)
seatIds.append(seatId)
if seatId > max:
max = seatId
totalSeats = 127 * 8 + 7
print(max)
print(findSantasSeat(findMissingPasses(seatIds, totalSeats), seatIds))