2017-12-02 - Corruption Checksum
(original .ipynb)puzzle_input_str = open("puzzle_input/day2.txt").read() def part_one(input_str): lines = input_str.split("\n") csum = 0 for line in lines: cols = [ int(col) for col in line.split("\t") ] min_col = min(cols) max_col = max(cols) csum += (max_col - min_col) return csum print("part one:", part_one(puzzle_input_str))
part one: 37923
def divisible(x, y): return x % y == 0 def values_excluding_index(lst, idx): values = lst[:idx] if idx < len(lst): values += lst[idx+1:] return values def part_two(input_str): lines = input_str.split("\n") csum = 0 for line in lines: cols = [ int(col) for col in line.split("\t") ] for i in range(len(cols)): col = cols[i] csum += sum([ int(col / n) for n in values_excluding_index(cols, i) if divisible(col, n) ]) return csum print("part two:", part_two(puzzle_input_str))
part two: 263