37 lines
983 B
Python
Executable File
37 lines
983 B
Python
Executable File
#!/usr/bin/env python3
|
|
import aoclib
|
|
import itertools
|
|
|
|
DAY = 1
|
|
|
|
|
|
def getProductOf2020Sum(input_lines, combinations):
|
|
return_value = 1
|
|
for check_tuple in itertools.combinations(input_lines, combinations):
|
|
if sum(check_tuple) == 2020:
|
|
for value in list(check_tuple):
|
|
return_value *= value
|
|
|
|
break
|
|
|
|
return return_value
|
|
|
|
|
|
@aoclib.print_execution_time
|
|
def part1(test_mode=False):
|
|
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
|
return getProductOf2020Sum(my_input, 2)
|
|
|
|
|
|
@aoclib.print_execution_time
|
|
def part2(test_mode=False):
|
|
my_input = aoclib.getInputAsArray(day=1, return_type=int, test=test_mode)
|
|
return getProductOf2020Sum(my_input, 3)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
assert part1(test_mode=True) == 514579, "Part 1 TEST FAILED"
|
|
aoclib.printSolution(DAY, 1, part1())
|
|
assert part2(test_mode=True) == 241861950, "Part 2 TEST FAILED"
|
|
aoclib.printSolution(DAY, 2, part2())
|