Skip to content

Commit

Permalink
chore: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelblijleven committed Dec 8, 2023
1 parent 0b742e0 commit 14155e7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 49 deletions.
14 changes: 2 additions & 12 deletions src/adventofcode/year_2023/day_06_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions src/adventofcode/year_2023/day_07_2023.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions src/adventofcode/year_2023/day_08_2023.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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)
4 changes: 3 additions & 1 deletion tests/adventofcode/year_2023/test_day_06_2023.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
48 changes: 27 additions & 21 deletions tests/adventofcode/year_2023/test_day_07_2023.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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

Expand Down
19 changes: 10 additions & 9 deletions tests/adventofcode/year_2023/test_day_08_2023.py
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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():
Expand All @@ -43,4 +44,4 @@ def test_part_one():


def test_part_two():
assert part_two(test_input) == 'x'
assert part_two(test_input) == "x"

0 comments on commit 14155e7

Please sign in to comment.