Skip to content

Instantly share code, notes, and snippets.

@RGamberini
Created December 3, 2015 22:49
Show Gist options
  • Save RGamberini/1a00547f39b114cda7e0 to your computer and use it in GitHub Desktop.
Save RGamberini/1a00547f39b114cda7e0 to your computer and use it in GitHub Desktop.
from operator import mul
def sqftBox(l,w,h):
return 2*l*w + 2*w*h + 2*h*l
def areaSmallestSide(l, w, h):
return min([l * w, l * h, w * h])
def perimeterSmallestSide(l, w, h):
return min([2*l + 2*w, 2*l + 2*h, 2*w + 2*h])
with open("input.txt") as _input:
wrappingPaper = 0
ribbon = 0
for line in _input:
dimensions = map(int, line.split("x"))
wrappingPaper += sqftBox(*dimensions) + areaSmallestSide(*dimensions)
ribbon += perimeterSmallestSide(*dimensions) + reduce(mul, dimensions)
print("Square feet of wrapping paper: " + str(wrappingPaper))
print("Feet of ribbon: " + str(ribbon))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment