Skip to content

Commit 73e2df3

Browse files
chore: format 2023 day 9
1 parent c091427 commit 73e2df3

File tree

2 files changed

+102
-23
lines changed

2 files changed

+102
-23
lines changed

src/adventofcode/year_2023/day_09_2023.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import re
2+
from collections.abc import Iterable
23
from functools import partial
34
from itertools import pairwise
45
from operator import itemgetter
5-
from typing import Iterable
66

7-
from adventofcode.util.exceptions import SolutionNotFoundError
87
from adventofcode.registry.decorators import register_solution
8+
from adventofcode.util.exceptions import SolutionNotFoundError
99
from adventofcode.util.input_helpers import get_input_for_day
1010

11-
1211
pattern = re.compile("-?\\d+")
1312

1413

@@ -31,7 +30,7 @@ def parse_input_reversed(data: list[str]) -> Iterable[Iterable[int]]:
3130
def find_next_in_sequence(sequence: Iterable[int], lines: list[list[int]] | None) -> int:
3231
numbers = list(sequence)
3332
lines = [numbers] if lines is None or len(lines) == 0 else lines
34-
differences = [y-x for (x, y) in pairwise(numbers)]
33+
differences = [y - x for (x, y) in pairwise(numbers)]
3534
lines.append(differences)
3635

3736
if any(differences):
@@ -72,7 +71,7 @@ def part_two(input_data: list[str]):
7271
return answer
7372

7473

75-
if __name__ == '__main__':
74+
if __name__ == "__main__":
7675
data = get_input_for_day(2023, 9)
7776
part_one(data)
7877
part_two(data)
Lines changed: 98 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from adventofcode.year_2023.day_09_2023 import part_two, part_one, parse_input, parse_sequence, find_next_in_sequence
3+
from adventofcode.year_2023.day_09_2023 import find_next_in_sequence, parse_input, parse_sequence, part_one, part_two
44

55
test_input = [
66
"0 3 6 9 12 15",
@@ -9,13 +9,19 @@
99
]
1010

1111

12-
@pytest.mark.parametrize(["sequence", "expected"], [
13-
("0 3 6 9 12 15", [0, 3, 6, 9, 12, 15]),
14-
("1 3 6 10 15 21", [1, 3, 6, 10, 15, 21]),
15-
("10 13 16 21 30 45", [10, 13, 16, 21, 30, 45]),
16-
("-1 -20 -300 400", [-1, -20, -300, 400]),
17-
("5 1 -3 -7 -11 -15 -19 -23 -27 -31 -35 -39 -43 -47 -51 -55 -59 -63 -67 -71 -75", [5, 1, -3, -7, -11, -15, -19, -23, -27, -31, -35, -39, -43, -47, -51, -55, -59, -63, -67, -71, -75]),
18-
])
12+
@pytest.mark.parametrize(
13+
["sequence", "expected"],
14+
[
15+
("0 3 6 9 12 15", [0, 3, 6, 9, 12, 15]),
16+
("1 3 6 10 15 21", [1, 3, 6, 10, 15, 21]),
17+
("10 13 16 21 30 45", [10, 13, 16, 21, 30, 45]),
18+
("-1 -20 -300 400", [-1, -20, -300, 400]),
19+
(
20+
"5 1 -3 -7 -11 -15 -19 -23 -27 -31 -35 -39 -43 -47 -51 -55 -59 -63 -67 -71 -75",
21+
[5, 1, -3, -7, -11, -15, -19, -23, -27, -31, -35, -39, -43, -47, -51, -55, -59, -63, -67, -71, -75],
22+
),
23+
],
24+
)
1925
def test_parse_sequence(sequence, expected):
2026
assert list(parse_sequence(sequence)) == expected
2127

@@ -24,15 +30,89 @@ def test_parse_input():
2430
assert len(list(parse_input(test_input))) == 3
2531

2632

27-
@pytest.mark.parametrize(["sequence", "expected"], [
28-
([13, 23, 46, 97, 206, 436, 919, 1924, 3971, 8016, 15765, 30243, 56875, 105604, 195153, 361805, 677725, 1289089,
29-
2494076, 4898137, 9713336], 19316320),
30-
([-7, 6, 44, 130, 309, 672, 1404, 2864, 5712, 11113, 21082, 39112, 71386, 129156, 233312, 422773, 769075,
31-
1400300, 2538072, 4551386, 8029995], 13877188
32-
),
33-
([5, 1, -3, -7, -11, -15, -19, -23, -27, -31, -35, -39, -43, -47, -51, -55, -59, -63, -67, -71, -75,
34-
], -79)
35-
])
33+
@pytest.mark.parametrize(
34+
["sequence", "expected"],
35+
[
36+
(
37+
[
38+
13,
39+
23,
40+
46,
41+
97,
42+
206,
43+
436,
44+
919,
45+
1924,
46+
3971,
47+
8016,
48+
15765,
49+
30243,
50+
56875,
51+
105604,
52+
195153,
53+
361805,
54+
677725,
55+
1289089,
56+
2494076,
57+
4898137,
58+
9713336,
59+
],
60+
19316320,
61+
),
62+
(
63+
[
64+
-7,
65+
6,
66+
44,
67+
130,
68+
309,
69+
672,
70+
1404,
71+
2864,
72+
5712,
73+
11113,
74+
21082,
75+
39112,
76+
71386,
77+
129156,
78+
233312,
79+
422773,
80+
769075,
81+
1400300,
82+
2538072,
83+
4551386,
84+
8029995,
85+
],
86+
13877188,
87+
),
88+
(
89+
[
90+
5,
91+
1,
92+
-3,
93+
-7,
94+
-11,
95+
-15,
96+
-19,
97+
-23,
98+
-27,
99+
-31,
100+
-35,
101+
-39,
102+
-43,
103+
-47,
104+
-51,
105+
-55,
106+
-59,
107+
-63,
108+
-67,
109+
-71,
110+
-75,
111+
],
112+
-79,
113+
),
114+
],
115+
)
36116
def test_find_next_in_sequence(sequence, expected):
37117
assert find_next_in_sequence(sequence, []) == expected
38118

@@ -42,4 +122,4 @@ def test_part_one():
42122

43123

44124
def test_part_two():
45-
assert part_two(test_input) == 'x'
125+
assert part_two(test_input) == "x"

0 commit comments

Comments
 (0)