From b868f6306016dd80a774eb7c9d63e976f2e4ba2a Mon Sep 17 00:00:00 2001 From: Akumatic Date: Sat, 5 Dec 2020 11:58:01 +0100 Subject: [PATCH] Shorten 2020 Day 05 --- 2020/05/code.py | 22 ++++++---------------- 2020/README.md | 2 +- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/2020/05/code.py b/2020/05/code.py index 5a46a71..70a272f 100644 --- a/2020/05/code.py +++ b/2020/05/code.py @@ -5,29 +5,19 @@ def readFile() -> list: with open(f"{__file__.rstrip('code.py')}input.txt", "r") as f: - return [line[:-1] for line in f.readlines()] - -def parse(seat) -> tuple: - return sum([2**(6-i) for i in range(7) if seat[i] in ("B")]), \ - sum([2**(9-i) for i in range(7, 10) if seat[i] in ("R")]) + return [int(line[:-1].replace("F", "0").replace("B", "1") + .replace("L", "0").replace("R", "1"), 2) for line in f.readlines()] def part1(seat_ids: list) -> int: return max(seat_ids) def part2(seat_ids: list) -> int: - for i in range(8, 1015): # front and back row skipped + for i in range(min(seat_ids), max(seat_ids)): if i not in seat_ids and (i - 1) in seat_ids and (i + 1) in seat_ids: return i -def test(): - assert parse("FBFBBFFRLR") == (44,5) - assert parse("BFFFBBFRRR") == (70,7) - assert parse("FFFBBBFRRR") == (14,7) - assert parse("BBFFBBFRLL") == (102,4) - if __name__ == "__main__": - test() - seats = [parse(val) for val in readFile()] - seat_ids = [seat[0]*8 + seat[1] for seat in seats] + seat_ids = readFile() print(f"Part 1: {part1(seat_ids)}") - print(f"Part 2: {part2(seat_ids)}") \ No newline at end of file + print(f"Part 2: {part2(seat_ids)}") + \ No newline at end of file diff --git a/2020/README.md b/2020/README.md index b80037f..c3309b1 100644 --- a/2020/README.md +++ b/2020/README.md @@ -17,7 +17,7 @@ Collect stars by solving puzzles. Two puzzles will be made available on each day | --- | --- | --- |---| --- | --- | --- | | 01 | :white_check_mark: | :white_check_mark: || 02 | :white_check_mark: | :white_check_mark: | | 03 | :white_check_mark: | :white_check_mark: || 04 | :white_check_mark: | :white_check_mark: | -| 05 | | || 06 | | | +| 05 | :white_check_mark: | :white_check_mark: || 06 | | | | 07 | | || 08 | | | | 09 | | || 10 | | | | 11 | | || 12 | | |