X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2020.git/blobdiff_plain/a2ce7bb47964e226d4b10b791a038ca1f1fa67d7..fe0197cb1dc8f701b69ce52b9acb445351557c8d:/day05/get_seat_id.py diff --git a/day05/get_seat_id.py b/day05/get_seat_id.py new file mode 100644 index 0000000..1b83889 --- /dev/null +++ b/day05/get_seat_id.py @@ -0,0 +1,63 @@ +#!/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))