28 lines
579 B
Python
28 lines
579 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))
|
||
|
|
||
|
seats.sort()
|
||
|
|
||
|
for i in range(len(seats)-1):
|
||
|
if seats[i] != seats[i+1]-1:
|
||
|
print(seats[i]+1)
|
||
|
break
|