2020-12-01 - Report Repair
(original .ipynb)
Day 1 puzzle input is a list of integers which represent expenses (mine is here). Part 1 involves finding a pair of these which sums to 2020
and returning the value of them multiplied together. Part 2 is the exact same but for triples instead of pairs.
from itertools import combinations puzzle_input_str = open("puzzle_input/day1.txt").read() test_input_str = """1721 979 366 299 675 1456""" def sum_equal_2020(x, y, z=0): return x + y + z == 2020 def part1(expenses_str): expenses = [ int(n) for n in expenses_str.split("\n") ] combos = combinations(expenses, 2) return [ x*y for (x,y) in combos if sum_equal_2020(x,y) ][0] assert 514579 == part1(test_input_str) part1(puzzle_input_str)
889779
def part2(expenses_str): expenses = [ int(n) for n in expenses_str.split("\n") ] combos = combinations(expenses, 3) return [ x*y*z for (x,y,z) in combos if sum_equal_2020(x,y,z) ][0] assert 241861950 == part2(test_input_str) part2(puzzle_input_str)
76110336