day9 optimizations
This commit is contained in:
parent
9bd530c097
commit
e666a78ba1
9
day09.py
9
day09.py
@ -15,8 +15,8 @@ def part1(test_mode=False):
|
||||
current_buffer_size = len(number_buffer)
|
||||
if current_buffer_size == max_buffer_size:
|
||||
found_sum = False
|
||||
for combination in itertools.combinations(number_buffer, 2):
|
||||
if sum(combination) == number:
|
||||
for check_number in number_buffer:
|
||||
if number - check_number in number_buffer:
|
||||
found_sum = True
|
||||
break
|
||||
|
||||
@ -36,10 +36,11 @@ def part2(test_mode=False):
|
||||
|
||||
for start_index in range(0, len(my_input)):
|
||||
for stop_index in range(start_index + 1, len(my_input) - start_index - 1):
|
||||
if my_input[stop_index] == sum_to_find:
|
||||
thisSum = sum(my_input[start_index:stop_index])
|
||||
if thisSum > sum_to_find:
|
||||
break
|
||||
|
||||
if sum(my_input[start_index:stop_index]) == sum_to_find:
|
||||
if thisSum == sum_to_find:
|
||||
return min(my_input[start_index:stop_index]) + max(my_input[start_index:stop_index])
|
||||
|
||||
return 0
|
||||
|
||||
Loading…
Reference in New Issue
Block a user