22 lines
494 B
Python
22 lines
494 B
Python
#!/usr/bin/env python
|
|
|
|
|
|
def compute_seat_pos(code, code_lower, code_upper, pos_max):
|
|
pos_min = 0
|
|
for i in code:
|
|
if i == code_lower:
|
|
pos_max = int((pos_min + pos_max-1)/2)
|
|
continue
|
|
if i == code_upper:
|
|
pos_min = int((pos_min + pos_max+1)/2)
|
|
continue
|
|
return pos_min
|
|
|
|
|
|
seats = []
|
|
with open("input01.txt","r") as f:
|
|
for line in f:
|
|
line = line.strip()
|
|
seats.append(compute_seat_pos(line[:7], "F", "B", 127) * 8 + compute_seat_pos(line[-3:], "L", "R", 7))
|
|
|
|
print(max(seats)) |