def part_two_solution(entries, tests=[]): answer = 1 for test in tests: num = part_one_solution(entries, test['right'], test['down']) answer *= num return answer
def test_part_one_solutions(self): entries = [ 'ecl:gry pid:860033327 eyr:2020 hcl:#fffffd', 'byr:1937 iyr:2017 cid:147 hgt:183cm', '', 'iyr:2013 ecl:amb cid:350 eyr:2023 pid:028048884', 'hcl:#cfa07d byr:1929', '', 'hcl:#ae17e1 iyr:2013', 'eyr:2024', 'ecl:brn pid:760753108 byr:1931', 'hgt:179cm', '', 'hcl:#cfa07d eyr:2025 pid:166559648', 'iyr:2011 ecl:brn hgt:59in' ] self.assertEqual(part_one_solution(entries), 2)
def part_two_solution(entries, preamble_size=25): solution = part_one_solution(entries, preamble_size) start = 0 end = len(entries) for index, num in enumerate(entries): total = [num] for element in entries[index + 1:]: total.append(element) total.sort() if sum(total) == solution: return total[0] + total[-1]
from util import read_file_to_list from part1 import part_one_solution from part2 import part_two_solution tests = [{ 'right': 1, 'down': 1 }, { 'right': 3, 'down': 1 }, { 'right': 5, 'down': 1 }, { 'right': 7, 'down': 1 }, { 'right': 1, 'down': 2 }] if __name__ == '__main__': inputs = read_file_to_list('input.txt') part_one_answer = part_one_solution(inputs) print(f"Part 1: {part_one_answer}") part_two_answer = part_two_solution(inputs, tests=tests) print(f'Part 2: {part_two_answer}')
def test_part_one_solutions(self): self.assertEqual(part_one_solution(self.entries), 37)
def test_part_one_solution(self): self.assertEqual(part_one_solution(self.entries), PART_ONE_ANSWER)
#!/usr/bin/env python from util import read_file_to_list from part1 import part_one_solution from part2 import part_two_solution if __name__ == '__main__': entries = read_file_to_list('input.txt') part_one_answer = part_one_solution(entries) print(f'Part 1: {part_one_answer}') part_two_answer = part_two_solution(entries) print(f'Part 2: {part_two_answer}')