#!/usr/bin/python3

def get_row(binary_id):
    choices=binary_id[:7]

    selections=[a for a in range(128)]

    for decision in choices:
        half_range=int(len(selections)/2)
        if decision == 'F':
            del selections[-half_range:]
        elif decision == 'B':
            del selections[:half_range]

    return selections[0]

def get_col(binary_id):
    choices=binary_id[-3:]

    selections=[a for a in range(8)]

    for decision in choices:
        half_range=int(len(selections)/2)
        if decision == 'L':
            del selections[-half_range:]
        elif decision == 'R':
            del selections[:half_range]

    return selections[0]

def get_seat(binary_id):
    row=get_row(binary_id)
    col=get_col(binary_id)

    return ((row,col))

def get_seat_id(row, col):
    return ((row * 8) + col)

all_seat_ids=[]

for line in open("input.txt", "r"):
    line = line.rstrip()

    (row, col) = get_seat(line)
    all_seat_ids.append(get_seat_id(row, col))

# sort the list
all_seat_ids.sort()

# and print the highest seat id - part 1
print("Highest seat id: {}".format(all_seat_ids[-1]))


# part 2
my_seat_id=None

for a,b in enumerate(all_seat_ids, start=all_seat_ids[0]):
    if a != b:
        my_seat_id=a
        break

print("My seat id: {}".format(my_seat_id))
