50 lines
951 B
Python
Executable File
50 lines
951 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# Advent Of Code 2020 - Day 5
|
|
|
|
"""
|
|
FBBFBBBRLR
|
|
BFFBBFFLLL
|
|
BFFBBBBRRR
|
|
BBBFBBFRLL
|
|
"""
|
|
|
|
filename = "input.txt"
|
|
|
|
with open(filename) as f:
|
|
content = f.readlines()
|
|
content = [x.strip() for x in content]
|
|
|
|
highestSeat = 0
|
|
uniqueIDs = []
|
|
|
|
for boardPass in content:
|
|
|
|
row = boardPass[:7]
|
|
row = row.replace('F','0')
|
|
row = row.replace('B','1')
|
|
row = int(row,2)
|
|
|
|
seat = boardPass[7:]
|
|
seat = seat.replace('L','0')
|
|
seat = seat.replace('R','1')
|
|
seat = int(seat, 2)
|
|
|
|
seatID = row * 8 + seat
|
|
|
|
highestSeat = max(highestSeat, seatID)
|
|
uniqueIDs.append(seatID)
|
|
|
|
allSeats = range(min(uniqueIDs), max(uniqueIDs))
|
|
|
|
|
|
missingSeat = list(set(allSeats).difference(uniqueIDs))[0]
|
|
|
|
# Elegant filter/lambda solution from the intenet
|
|
#missingSeat = list(filter(lambda x: x+1 in uniqueIDs and x-1 in uniqueIDs and x not in uniqueIDs, allSeats))[0]
|
|
|
|
|
|
print("Part 1:",highestSeat)
|
|
print("Part 2:",missingSeat)
|
|
|