summaryrefslogtreecommitdiff
path: root/day5/day5.py
blob: b544b61573c9a24e3609f4739b3caee662daa1ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
"""Peter Norvig solution. Forgot to do day 5."""
data = map(str.strip, open("input"))

ID = int

def seat_id(seat: str, table=str.maketrans('FLBR', '0011')) -> ID:
    "Treat a seat description as a binary number; convert to int."
    return ID(seat.translate(table), base=2)


ids = [seat_id(x) for x in data]

# Part 1
print(max(ids))

# Part 2
[missing] = set(range(min(ids), max(ids))) - set(ids)
print(missing)