diff --git a/2023/day06/solution.py b/2023/day06/solution.py index 0f6cd0f..77d3a18 100644 --- a/2023/day06/solution.py +++ b/2023/day06/solution.py @@ -4,7 +4,7 @@ INPUTS_FILE = Path(__file__).parent / "input.txt" -def parse(input_str: str) -> None: +def parse(input_str: str, concat: bool) -> None: times = [] distances = [] for line in input_str.splitlines(): @@ -18,7 +18,15 @@ def parse(input_str: str) -> None: elif line.startswith("Distance:"): distances.extend(int(d) for d in line.split()[1:]) - races = list(zip(times, distances)) + if not concat: + races = list(zip(times, distances)) + else: + races = [ + ( + int("".join(str(t) for t in times)), + int("".join(str(d) for d in distances)), + ) + ] return races @@ -34,9 +42,8 @@ def count_ways_to_win(time, distance): return time - (t * 2) + 1 -def calculate(input_str: str) -> int: - print() - races = parse(input_str) +def calculate(input_str: str, concat: bool = False) -> int: + races = parse(input_str, concat=concat) ways_to_win = [] for time, distance in races: @@ -50,7 +57,7 @@ def main() -> None: with INPUTS_FILE.open() as fp: input_str = fp.read() print(f"The answer to part 1 is {calculate(input_str)}") - print(f"The answer to part 2 is {calculate(input_str)}") + print(f"The answer to part 2 is {calculate(input_str, concat=True)}") if __name__ == "__main__": diff --git a/2023/day06/tests.py b/2023/day06/tests.py index f05f331..86410fb 100644 --- a/2023/day06/tests.py +++ b/2023/day06/tests.py @@ -25,31 +25,12 @@ def test_part1(input_str: str, expected: int) -> None: assert calculate(input_str) == expected -# @pytest.mark.parametrize( -# "input_str,expected", -# [ -# pytest.param(TEST_INPUT, 46, id="test-input"), -# pytest.param(REAL_INPUT, 24261545, id="real-data"), -# ], -# ) -# def test_part2(input_str: str, expected: int) -> None: -# assert calculate(input_str, ranges=True) == expected -# -# -# @pytest.mark.parametrize( -# "rng, expected_result", -# [ -# pytest.param((0, 49), {(0, 49)}, id="no-overlap"), -# pytest.param((55, 74), {(57, 76)}, id="map-overlaps_range"), -# pytest.param((55, 85), {(57, 77), (76, 85)}, id="partial-overlap-left"), -# pytest.param((40, 70), {(40, 49), (52, 72)}, id="partial-overlap-right"), -# pytest.param((40, 85), {(40, 49), (52, 77), (76, 85)}, id="range-overlaps-map"), -# ], -# ) -# def test_apply_maps_to_range(rng, expected_result): -# maps = [ -# (50, 98, 2), # {98 - 99}, -48 -# (52, 50, 26), # {50 - 75}, +2 -# ] -# result = apply_maps_to_range(rng, maps) -# assert result == expected_result +@pytest.mark.parametrize( + "input_str,expected", + [ + pytest.param(TEST_INPUT, 71503, id="test-input"), + pytest.param(REAL_INPUT, 27102791, id="real-data"), + ], +) +def test_part2(input_str: str, expected: int) -> None: + assert calculate(input_str, concat=True) == expected