From 14155e76b6a2c0bc95471e1f63e89ccdddfaf5d6 Mon Sep 17 00:00:00 2001 From: Marcel Blijleven Date: Fri, 8 Dec 2023 21:23:22 +0100 Subject: [PATCH] chore: formatting --- src/adventofcode/year_2023/day_06_2023.py | 14 +----- src/adventofcode/year_2023/day_07_2023.py | 7 ++- src/adventofcode/year_2023/day_08_2023.py | 4 +- .../year_2023/test_day_06_2023.py | 4 +- .../year_2023/test_day_07_2023.py | 48 +++++++++++-------- .../year_2023/test_day_08_2023.py | 19 ++++---- 6 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/adventofcode/year_2023/day_06_2023.py b/src/adventofcode/year_2023/day_06_2023.py index 6c8fe4e..b94f816 100644 --- a/src/adventofcode/year_2023/day_06_2023.py +++ b/src/adventofcode/year_2023/day_06_2023.py @@ -92,8 +92,8 @@ def calculate_margin_of_error_quadratic(data: list[str]) -> int: """ duration, distance = parse_input_part_two(data) discriminant = duration * duration - 4 * distance - lower_bound = math.ceil((-duration + math.sqrt(discriminant)) / - 2) - upper_bound = math.floor((-duration - math.sqrt(discriminant)) / - 2) + lower_bound = math.ceil((-duration + math.sqrt(discriminant)) / -2) + upper_bound = math.floor((-duration - math.sqrt(discriminant)) / -2) total = 0 @@ -138,16 +138,6 @@ def part_two_quadratic(input_data: list[str]): return answer -@register_solution(2023, 6, 2, version="quadratic") -def part_two_quadratic(input_data: list[str]): - answer = calculate_margin_of_error_quadratic(input_data) - - if not answer: - raise SolutionNotFoundError(2023, 6, 2) - - return answer - - if __name__ == "__main__": data = get_input_for_day(2023, 6) part_one(data) diff --git a/src/adventofcode/year_2023/day_07_2023.py b/src/adventofcode/year_2023/day_07_2023.py index 687b5f1..1c2ef29 100644 --- a/src/adventofcode/year_2023/day_07_2023.py +++ b/src/adventofcode/year_2023/day_07_2023.py @@ -1,13 +1,12 @@ from collections import Counter, deque +from collections.abc import Iterable from functools import cmp_to_key, partial from itertools import starmap -from typing import Iterable -from adventofcode.util.exceptions import SolutionNotFoundError from adventofcode.registry.decorators import register_solution +from adventofcode.util.exceptions import SolutionNotFoundError from adventofcode.util.input_helpers import get_input_for_day - cards = { "A": 13, "K": 12, @@ -145,7 +144,7 @@ def part_two(input_data: list[str]): return answer -if __name__ == '__main__': +if __name__ == "__main__": data = get_input_for_day(2023, 7) part_one(data) part_two(data) diff --git a/src/adventofcode/year_2023/day_08_2023.py b/src/adventofcode/year_2023/day_08_2023.py index 945f616..1d83fcb 100644 --- a/src/adventofcode/year_2023/day_08_2023.py +++ b/src/adventofcode/year_2023/day_08_2023.py @@ -1,8 +1,8 @@ import re from collections import deque -from adventofcode.util.exceptions import SolutionNotFoundError from adventofcode.registry.decorators import register_solution +from adventofcode.util.exceptions import SolutionNotFoundError from adventofcode.util.input_helpers import get_input_for_day @@ -56,7 +56,7 @@ def part_two(input_data: list[str]): return answer -if __name__ == '__main__': +if __name__ == "__main__": data = get_input_for_day(2023, 8) part_one(data) part_two(data) diff --git a/tests/adventofcode/year_2023/test_day_06_2023.py b/tests/adventofcode/year_2023/test_day_06_2023.py index 8bbf9d6..264b435 100644 --- a/tests/adventofcode/year_2023/test_day_06_2023.py +++ b/tests/adventofcode/year_2023/test_day_06_2023.py @@ -3,9 +3,11 @@ from adventofcode.year_2023.day_06_2023 import ( calculate_distance, calculate_ways_to_win, + calculate_ways_to_win_part_two, parse_input, + parse_input_part_two, part_one, - part_two, parse_input_part_two, calculate_ways_to_win_part_two, + part_two, ) test_input = [ diff --git a/tests/adventofcode/year_2023/test_day_07_2023.py b/tests/adventofcode/year_2023/test_day_07_2023.py index 12df417..a57d9de 100644 --- a/tests/adventofcode/year_2023/test_day_07_2023.py +++ b/tests/adventofcode/year_2023/test_day_07_2023.py @@ -1,6 +1,6 @@ import pytest -from adventofcode.year_2023.day_07_2023 import part_two, part_one, parse_input, parse_hand, hands +from adventofcode.year_2023.day_07_2023 import hands, parse_hand, parse_input, part_one, part_two test_input = [ "32T3K 765", @@ -21,30 +21,36 @@ def test_parse_input(): ] -@pytest.mark.parametrize(["hand", "expected"], [ - ("32T3K", hands["One pair"]), - ("T55J5", hands["Three of a kind"]), - ("KK677", hands["Two pair"]), - ("KTJJT", hands["Two pair"]), - ("QQQJA", hands["Three of a kind"]), - ("AAAAA", hands["Five of a kind"]), - ("AAAAK", hands["Four of a kind"]), - ("AAAKK", hands["Full house"]), -]) +@pytest.mark.parametrize( + ["hand", "expected"], + [ + ("32T3K", hands["One pair"]), + ("T55J5", hands["Three of a kind"]), + ("KK677", hands["Two pair"]), + ("KTJJT", hands["Two pair"]), + ("QQQJA", hands["Three of a kind"]), + ("AAAAA", hands["Five of a kind"]), + ("AAAAK", hands["Four of a kind"]), + ("AAAKK", hands["Full house"]), + ], +) def test_parse_hand(hand, expected): assert parse_hand(hand, with_jokers=False) == expected -@pytest.mark.parametrize(["hand", "expected"], [ - ("32T3K", hands["One pair"]), - ("T55J5", hands["Four of a kind"]), - ("KK677", hands["Two pair"]), - ("KTJJT", hands["Four of a kind"]), - ("QQQJA", hands["Four of a kind"]), - ("AAAAA", hands["Five of a kind"]), - ("AAAAK", hands["Four of a kind"]), - ("AAAKK", hands["Full house"]), -]) +@pytest.mark.parametrize( + ["hand", "expected"], + [ + ("32T3K", hands["One pair"]), + ("T55J5", hands["Four of a kind"]), + ("KK677", hands["Two pair"]), + ("KTJJT", hands["Four of a kind"]), + ("QQQJA", hands["Four of a kind"]), + ("AAAAA", hands["Five of a kind"]), + ("AAAAK", hands["Four of a kind"]), + ("AAAKK", hands["Full house"]), + ], +) def test_parse_hand_with_joker(hand, expected): assert parse_hand(hand, with_jokers=True) == expected diff --git a/tests/adventofcode/year_2023/test_day_08_2023.py b/tests/adventofcode/year_2023/test_day_08_2023.py index 887c419..bcba60f 100644 --- a/tests/adventofcode/year_2023/test_day_08_2023.py +++ b/tests/adventofcode/year_2023/test_day_08_2023.py @@ -1,8 +1,6 @@ from collections import deque -from adventofcode.year_2023.day_08_2023 import part_two, part_one, parse_input, follow_instructions - - +from adventofcode.year_2023.day_08_2023 import follow_instructions, parse_input, part_one, part_two test_input = [ "RL", @@ -26,11 +24,14 @@ def test_parse_input(): - assert parse_input(test_input_2) == (deque("LLR"), { - "AAA": ("BBB", "BBB"), - "BBB": ("AAA", "ZZZ"), - "ZZZ": ("ZZZ", "ZZZ"), - }) + assert parse_input(test_input_2) == ( + deque("LLR"), + { + "AAA": ("BBB", "BBB"), + "BBB": ("AAA", "ZZZ"), + "ZZZ": ("ZZZ", "ZZZ"), + }, + ) def test_follow_instructions(): @@ -43,4 +44,4 @@ def test_part_one(): def test_part_two(): - assert part_two(test_input) == 'x' + assert part_two(test_input) == "x"