build in asserts when running single day scripts
This commit is contained in:
parent
d49d0bb8fe
commit
f70c759582
28
day01.py
28
day01.py
@ -1,30 +1,32 @@
|
||||
#!/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
|
||||
|
||||
return return_value
|
||||
|
||||
|
||||
def part1(test_mode=False):
|
||||
my_input = aoclib.getInputLineAsArray(day=1, return_type=int, test=test_mode)
|
||||
while len(my_input) > 0:
|
||||
try_value = my_input.pop()
|
||||
for value in my_input:
|
||||
if try_value + value == 2020:
|
||||
return try_value * value
|
||||
return getProductOf2020Sum(my_input, 2)
|
||||
|
||||
|
||||
def part2(test_mode=False):
|
||||
my_input = aoclib.getInputLineAsArray(day=1, return_type=int, test=test_mode)
|
||||
while len(my_input) > 0:
|
||||
try_value = my_input.pop()
|
||||
for value_1 in my_input:
|
||||
for value_2 in my_input:
|
||||
if value_1 == value_2:
|
||||
continue
|
||||
if try_value + value_1 + value_2 == 2020:
|
||||
return try_value * value_1 * value_2
|
||||
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())
|
||||
|
||||
5
day02.py
5
day02.py
@ -24,13 +24,14 @@ def part2(test_mode=False):
|
||||
for line in my_input:
|
||||
match = re.match(splitter, line)
|
||||
(min_count, max_count, character, password) = match.group(1, 2, 3, 4)
|
||||
if (password[int(min_count) - 1] == character or password[int(max_count) - 1] == character) \
|
||||
and password[int(min_count) - 1] != password[int(max_count) - 1]:
|
||||
if (password[int(min_count) - 1] == character) ^ (password[int(max_count) - 1] == character):
|
||||
valid_count = valid_count + 1
|
||||
|
||||
return valid_count
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
assert part1(test_mode=True) == 2, "Part 1 TEST FAILED"
|
||||
aoclib.printSolution(DAY, 1, part1())
|
||||
assert part2(test_mode=True) == 1, "Part 2 TEST FAILED"
|
||||
aoclib.printSolution(DAY, 2, part2())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user