Skip to content

Commit

Permalink
chore: add second method for day 10 of 2015
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelblijleven committed Dec 6, 2022
1 parent 5b30f76 commit bf7b259
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
20 changes: 20 additions & 0 deletions src/adventofcode/year_2015/day_10_2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def iterate(value: str) -> str:
return new_value


def iterate_method_2(value: str) -> str:
return "".join(str(len(list(group))) + key for key, group in groupby(value))


@register_solution(2015, 10, 1)
def part_one(input_data: list[str]):
value = input_data[0]
Expand Down Expand Up @@ -46,7 +50,23 @@ def part_two(input_data: list[str]):
return answer


@register_solution(2015, 10, 2, "method 2")
def part_two_method_2(input_data: list[str]):
value = input_data[0]

for i in range(0, 50):
value = iterate_method_2(value)

answer = len(value)

if not answer:
raise SolutionNotFoundException(2015, 10, 2)

return answer


if __name__ == "__main__":
data = get_input_for_day(2015, 10)
part_one(data)
part_two(data)
part_two_method_2(data)
25 changes: 8 additions & 17 deletions tests/adventofcode/year_2015/test_day_10_2015.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import os
import sys

import pytest

from adventofcode.util.input_helpers import get_input_for_day
from adventofcode.year_2015.day_10_2015 import (
iterate,
part_two,
part_one,
get_input_for_day,
)


def should_skip() -> bool:
major, minor, micro, releaselevel, serial = sys.version_info
if major == 3 and minor == 11 and os.getenv("CI", False):
return True

return False
part_two_method_2,
) # noqa


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


@pytest.mark.skipif(
should_skip() == "true",
reason="For some reason, this test takes 23 minutes on 3.11 in Github Actions, but runs fine on earlier versions",
)
@pytest.mark.skip(reason="extremely slow in CI with Python 3.11")
def test_part_two():
assert part_two(get_input_for_day(2015, 10)) == 4666278


def test_part_two_method_2():
assert part_two_method_2(get_input_for_day(2015, 10)) == 4666278

0 comments on commit bf7b259

Please sign in to comment.