From 4bb6f8d06c0e384f3394012b1d48da58ed28cc5e Mon Sep 17 00:00:00 2001 From: Yigit Sever Date: Sun, 12 Dec 2021 01:24:32 +0300 Subject: 2020, tracking --- 2020/day5/boarding.py | 52 ++++ 2020/day5/input | 824 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 876 insertions(+) create mode 100644 2020/day5/boarding.py create mode 100644 2020/day5/input (limited to '2020/day5') diff --git a/2020/day5/boarding.py b/2020/day5/boarding.py new file mode 100644 index 0000000..336cd63 --- /dev/null +++ b/2020/day5/boarding.py @@ -0,0 +1,52 @@ +import math + +seat_ids = list() + +with open("input", "r") as passes: + + for seat in passes: + front = 0 + back = 127 + + left = 0 + right = 7 + + for i in seat: + if i == "F": + back = math.floor((front + back) / 2) + elif i == "B": + front = math.ceil((front + back) / 2) + elif i == "L": + right = math.floor((right + left) / 2) + else: + left = math.ceil((right + left) / 2) + + assert front == back + assert left == right + + row = front + col = left + + seat_id = row * 8 + col + + seat_ids.append(seat_id) + +seat_ids.sort() + +# answer to the first part +print(seat_ids[-1]) + +# answer to the second part +lent = len(seat_ids) +left = 0 +right = lent - 1 +cursor = 0 + +while right - left > 1: + cursor = math.ceil((left + right) / 2) + if (seat_ids[left] - left) != (seat_ids[cursor] - cursor): + right = cursor + elif (seat_ids[right] - right) != (seat_ids[cursor] - cursor): + left = cursor + +print(seat_ids[cursor] + 1) diff --git a/2020/day5/input b/2020/day5/input new file mode 100644 index 0000000..6ef4cd6 --- /dev/null +++ b/2020/day5/input @@ -0,0 +1,824 @@ +FFBBBFBLRL +BFFFBFBRRR +BFFFBFBLRL +BFFBFBBLRR +BBFFBFFRLL +BFFFBFBRLR +FFFFBBBRLR +BBFFFBBRRR +BBFBFBBRRR +BFFBBBFLRR +FFBBFBBRLR +BBFFBFFLLL +BFFFBFBLLR +FBBFFBFLRR +FBBFBBFRRL +BFFBBBBRRR +BFBBBBFLLL +BFFBFBFLRR +FBBFFBFRRR +FFBFBFBLRL +BFFFFBFLR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