finally it clicked for d9p2
This commit is contained in:
parent
490978ff9b
commit
cd78620ec3
19
day09.py
19
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])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user