Skip to content

Commit bf7b259

Browse files
chore: add second method for day 10 of 2015
1 parent 5b30f76 commit bf7b259

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

src/adventofcode/year_2015/day_10_2015.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ def iterate(value: str) -> str:
1616
return new_value
1717

1818

19+
def iterate_method_2(value: str) -> str:
20+
return "".join(str(len(list(group))) + key for key, group in groupby(value))
21+
22+
1923
@register_solution(2015, 10, 1)
2024
def part_one(input_data: list[str]):
2125
value = input_data[0]
@@ -46,7 +50,23 @@ def part_two(input_data: list[str]):
4650
return answer
4751

4852

53+
@register_solution(2015, 10, 2, "method 2")
54+
def part_two_method_2(input_data: list[str]):
55+
value = input_data[0]
56+
57+
for i in range(0, 50):
58+
value = iterate_method_2(value)
59+
60+
answer = len(value)
61+
62+
if not answer:
63+
raise SolutionNotFoundException(2015, 10, 2)
64+
65+
return answer
66+
67+
4968
if __name__ == "__main__":
5069
data = get_input_for_day(2015, 10)
5170
part_one(data)
5271
part_two(data)
72+
part_two_method_2(data)
Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
import os
2-
import sys
3-
41
import pytest
52

3+
from adventofcode.util.input_helpers import get_input_for_day
64
from adventofcode.year_2015.day_10_2015 import (
75
iterate,
86
part_two,
97
part_one,
10-
get_input_for_day,
11-
)
12-
13-
14-
def should_skip() -> bool:
15-
major, minor, micro, releaselevel, serial = sys.version_info
16-
if major == 3 and minor == 11 and os.getenv("CI", False):
17-
return True
18-
19-
return False
8+
part_two_method_2,
9+
) # noqa
2010

2111

2212
@pytest.mark.parametrize(
@@ -39,9 +29,10 @@ def test_part_one():
3929
assert part_one(get_input_for_day(2015, 10)) == 329356
4030

4131

42-
@pytest.mark.skipif(
43-
should_skip() == "true",
44-
reason="For some reason, this test takes 23 minutes on 3.11 in Github Actions, but runs fine on earlier versions",
45-
)
32+
@pytest.mark.skip(reason="extremely slow in CI with Python 3.11")
4633
def test_part_two():
4734
assert part_two(get_input_for_day(2015, 10)) == 4666278
35+
36+
37+
def test_part_two_method_2():
38+
assert part_two_method_2(get_input_for_day(2015, 10)) == 4666278

0 commit comments

Comments
 (0)