2015-12-02 - I Was Told There Would Be No Math
(original .ipynb)
Puzzle input is a sequence of (length,width,height) dimensions of presents. For part one we have to find the area of wrapping paper required (surface area of present + slack, where the slack is one unit of the smallest side). Part two involves finding the length of ribbon required (smallest distance around the present + some length for the bow, where the bow length is same magnitude as volume but in feet)
puzzle_input = open("./puzzle_input/day2.txt").readlines() def parse_input(input_lines): for line in input_lines: yield list(map(int, line.split("x"))) def calc_area(present): s1, s2 = sorted(present)[:2] l, w, h = present return (2*l*w) + (2*w*h) + (2*h*l) + (s1*s2) def part_one(input_lines): presents = parse_input(input_lines) return sum(map(calc_area, presents)) assert 58 == part_one(["2x3x4"]) assert 43 == part_one(["1x1x10"]) print("part one:", part_one(puzzle_input))
part one: 1586300
def ribbon_length(present): s1, s2 = sorted(present)[:2] l, w, h = present return (l*w*h) + (2*s1) + (2*s2) def part_two(input_lines): presents = parse_input(input_lines) return sum(map(ribbon_length, presents)) assert 34 == part_two(["2x3x4"]) assert 14 == part_two(["1x1x10"]) print("part two:", part_two(puzzle_input))
part two: 3737498