Skip to content

Instantly share code, notes, and snippets.

Created Dec 2, 2015
What would you like to do?
Advent of Code Day 2
from itertools import combinations
import operator
def wrapNeeded(dims):
sides = combinations(dims,2)
halfAreas = map(lambda (a,b): a*b, sides)
return sum(halfAreas)*2 + min(halfAreas)
def ribbonNeeded(dims):
dims = sorted(dims)
smallTwo = dims[0:2]
volume = reduce(operator.mul,dims,1)
return sum(smallTwo)*2 + volume
if __name__ == "__main__":
input = "" # Omitted
totalPaper = 0
totalRibbon = 0
for spec in input.split("\n"):
dims = [int(d) for d in spec.split("x")]
totalPaper += wrapNeeded(dims)
totalRibbon += ribbonNeeded(dims)
print "paper",totalPaper
print "ribbon",totalRibbon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment