-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday5.py
More file actions
24 lines (16 loc) · 753 Bytes
/
Copy pathday5.py
File metadata and controls
24 lines (16 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from common_py import input_access
input = input_access.fetch_input(5)
boardingPasses = input.rstrip().split("\n")
def mapToBinary(input):
return "".join(map(lambda c: "1" if c == "B" or c == "R" else "0", input))
def convertBinaryToInt(binaryInput):
return int(binaryInput, 2)
seatsInBinary = map(lambda x: (mapToBinary(x[0:7]), mapToBinary(x[7:])), boardingPasses)
seats = map(lambda seat : (convertBinaryToInt(seat[0]), convertBinaryToInt(seat[1])), seatsInBinary)
seatIds = set(map(lambda seat : seat[0] * 8 + seat[1], seats))
highestSeatId = max(seatIds)
print("part1 highest seat id:", highestSeatId)
for seatId in seatIds:
if seatId + 2 in seatIds and seatId + 1 not in seatIds:
print("part2 seat found", seatId + 1)
break