#Skip to menu

Day 2, Year 2015: I Was Told There Would Be No Math

First read the problem description.
def wrapping_paper_area(l, w, h):
    side_area = [l*w, w*h, h*l]
    surface_area = 2 * sum(side_area)
    slack = min(side_area)
    return surface_area + slack

def total_wrapping_paper_area(iter):
    return sum((wrapping_paper_area(*l) for l in iter))

def string_to_list(s):
    return (map(int, l.split('x')) 
            for l in s.splitlines())

def ribbon_length(l, w, h):
    if l >= w and l >= h:
        smaller_dimensions = (w, h)
        
    if w >= l and w >= h:
        smaller_dimensions = (l, h)
        
    if h >= l and h >= w:
        smaller_dimensions = (l, w)
        
    return 2*sum(smaller_dimensions) + l*w*h

def total_ribbon_length(iter):
    return sum((ribbon_length(*l) for l in iter))
assert wrapping_paper_area(2, 3, 4) == 58
assert wrapping_paper_area(1, 1, 10) == 43
import import_ipynb
import helper
s = helper.read_file('2015_2.txt')
total_wrapping_paper_area(string_to_list(s))
1586300
assert ribbon_length(2, 3, 4) == 34
assert ribbon_length(1, 1, 10) == 14
total_ribbon_length(string_to_list(s))
3737498

Source code of the solution(s):