advent-of-code/2015/day02.py

51 lines
986 B
Python
Raw Normal View History

2022-12-09 21:41:14 +00:00
import shared
from collections import Counter
def get_paper(l,w,h):
sides = [
(l*w),
(w*h),
(h*l)
]
smallest = min(sides)
sides = [2*x for x in sides]
sides.append(smallest)
return sum(sides)
def pt1(boxes):
box_papers = []
for box in boxes:
size = get_paper(*box)
box_papers.append(size)
print(sum(box_papers))
def get_ribbon(l,w,h):
dims = sorted([l,w,h])[:-1]
ribbon = sum([2*x for x in dims])
ribbon += (l*w*h)
return ribbon
def pt2(boxes):
box_ribbons = []
for box in boxes:
size = get_ribbon(*box)
box_ribbons.append(size)
print(sum(box_ribbons))
def main():
test = [[2,3,4]]
pt1(test)
pt2(test)
print('---')
with open(shared.get_fname(2), "r") as f:
inp = [x.rstrip() for x in f.readlines()]
boxes = [list(map(int,x.split("x"))) for x in inp]
pt1(boxes)
pt2(boxes)
if __name__ == "__main__":
main()