from itertools import count from helpers import get_aoc_data, defaultdict d = get_aoc_data(day=13) depth_ranges = dict(d.parsed('<int>: <int>')) # sort smallest modulo first depth_range_list = sorted([ (j, (k - 1) * 2) for (j, k) in depth_ranges.items() ], key=lambda x: x[1]) def part1(): severity = 0 for j, mod in depth_range_list: if j % mod == 0: severity += j * depth_ranges[j] return severity def part2(): for i in count(): for j, mod in depth_range_list: if (i + j) % mod == 0: break else: break return i
from itertools import permutations from helpers import get_aoc_data d = get_aoc_data(day=2) def part1(): return sum(max(row) - min(row) for row in d.integer_matrix) def part2(): the_sum = 0 for row in d.integer_matrix: for i1, i2 in permutations(row, 2): if not i2 % i1: the_sum += i2 // i1 break return the_sum