From 9dd918bad0aabd1f5242893b031f55068f0b66ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Mon, 7 Dec 2020 13:59:31 +0100 Subject: [PATCH] Day 5 --- 2020/5/data.txt | 816 ++++++++++++++++++++++++++++++++++++++++++++++++ 2020/5/main.py | 52 +++ 2 files changed, 868 insertions(+) create mode 100644 2020/5/data.txt create mode 100644 2020/5/main.py diff --git a/2020/5/data.txt b/2020/5/data.txt new file mode 100644 index 0000000..d9e3a32 --- /dev/null +++ b/2020/5/data.txt @@ -0,0 +1,816 @@ +FBFBFBFRRL +BFBBFFFRRL +FFBFFFFRLL +BFFFBBBRLL +BBFFBFBLLR +FFFFBBBRLR +FBBBBFFLRR +FBFFFBFRLL +FFFFBFFRRR +FFFBBFFRLR +BFBBBBFRLL +FBBFBFFLLL +FFFBFFBRRL +BFBFFBBLLL +FFBBFBBLLR +FFBFFBBRRL +BFBFBBBRRL +FFBFFBBLLL +BFFFBBBLRR +BFBFFBFRRR +BFFBFFBRRL +BFBFFFFLLR +FFFFBBBLRR +FFBBFBFRRR +BFFFBFBLLL +FBFFBBBRRL +FBBBBBBRRL +BBFBFFBLLL +BFFBFFFLLL +FBFFBBFLLR +FBFBFFBLRL +FFBFFFBRLR +FFBBBBFRLL +FBFBFFFLRL +FBBFBBFRLR +FFBBBBBLLL +FBFFBFBLLL +FBFFFBBRRR +BBFFBBFRRR +FBFFBFBRLL +FBBBFBBRRR +BFFFBFFRRL +FFBFBFBLLL +FBFBFFFRLR +FBBFBBBLLL +FFFBBBBLLL +FFFBFFBLLL +BFBFFBBLRR +FFBBFFFLLR +FFBBBBBLRR +BBFFFFBRLL +BFFFBBFLRR +BFBFFFBRRR +FBBFFFBLRR +BFBFBFFLLL +FBBFFBFRLL +FFBBBBFLRL +BFFFFBFLLR +FBFBBBFLLR +FFFBBFBRLL +FFBFFBBRLL +BFBBFFBRRR +FFFFBFBRLL +FBFFFBFRRL +FBBFFBBLLR +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RR +FBFBFBFLLR +BFFFFBFLRR +BFFFFBBRLL +FBBBBBBRLL +FBBBBBFRLR +BFFFBFBLRL diff --git a/2020/5/main.py b/2020/5/main.py new file mode 100644 index 0000000..791e2b3 --- /dev/null +++ b/2020/5/main.py @@ -0,0 +1,52 @@ +import math + +def get(s, l, u, ltok, utok): + if l == u: + return l + + c = s[:1] + h = math.ceil((u - l) / 2) + assert c in (ltok, utok) + if c == ltok: + return get(s[1:], l, u - h, ltok, utok) + return get(s[1:], l + h, u, ltok, utok) + + +def seat(s): + row = get(s[:7], 0, 127, "F", "B") + col = get(s[7:10], 0, 7, "L", "R") + return row, col + + +def seat_id(row, col): + return row * 8 + col + + +def missing_seat(seats): + a = sorted(seats) + b = range(a[0], a[-1]) + missing = set(b) - set(a) + assert len(missing) == 1 + return missing.pop() + + +assert seat("FBFBBFFRLR") == (44, 5) + +assert seat("BFFFBBFRRR") == (70, 7) +assert seat_id(70, 7) == 567 +assert seat("FFFBBBFRRR") == (14, 7) +assert seat_id(14, 7) == 119 +assert seat("BBFFBBFRLL") == (102, 4) +assert seat_id(102, 4) == 820 + +assert seat("BBFBFBFLLL") == (106, 0) + + +with open("data.txt", "r", encoding="utf-8") as f: + lines = f.readlines() + +seats = [seat_id(*seat(x.rstrip())) for x in lines] +sid_max = max(seats) + +print(f"Highest seat ID: {sid_max}") +print(f"Your seat is : {missing_seat(seats)}")