diff --git a/day09.py b/day09.py index cce1adf..11ec6a3 100644 --- a/day09.py +++ b/day09.py @@ -1,5 +1,4 @@ import aoclib -import itertools DAY = 9 TEST_SOLUTION_PART1 = 127 @@ -34,13 +33,15 @@ def part2(test_mode=False): my_input = aoclib.getInputAsArray(day=DAY, return_type=int, test=test_mode) sum_to_find = part1(test_mode) - for start_index in range(0, len(my_input)): - for stop_index in range(start_index + 1, len(my_input) - start_index - 1): - thisSum = sum(my_input[start_index:stop_index]) - if thisSum > sum_to_find: - break + start_index = 0 + stop_index = 1 + thisSum = sum(my_input[start_index:stop_index]) + while thisSum != sum_to_find: + if thisSum > sum_to_find: + start_index += 1 + else: + stop_index += 1 - if thisSum == sum_to_find: - return min(my_input[start_index:stop_index]) + max(my_input[start_index:stop_index]) + thisSum = sum(my_input[start_index:stop_index]) - return 0 + return min(my_input[start_index:stop_index]) + max(my_input[start_index:stop_index])