39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
'''AoC day 2'''
|
|
|
|
def get_surface_area(l: int, w: int, h: int) -> int:
|
|
'''Take the dimensions of the box and return its surface area
|
|
|
|
Keyword args:
|
|
l (int) - Length
|
|
w (int) - Width
|
|
h (int) - Height
|
|
'''
|
|
return 2*l*w + 2*w*h + 2*h*l
|
|
|
|
def get_slack_amount(l: int, w: int, h: int) -> int:
|
|
'''Take dimensions and return the value of the smallest'''
|
|
return min([l*w, w*h, h*l])
|
|
|
|
def get_ribbon_amount(l: int, w: int, h: int) -> int:
|
|
return min([2*h + 2*w, 2*l + 2*w, 2*h + 2*l]) + (l*w*h)
|
|
|
|
def main():
|
|
'''Entrypoint'''
|
|
# Surface area for wrapping paper
|
|
with open('input.txt', encoding='utf-8') as fh:
|
|
sum = 0
|
|
r_sum = 0
|
|
|
|
for line in fh:
|
|
l, w, h = [int(x) for x in line.split('x')]
|
|
# print(f'{l} {w} {h}')
|
|
sum += get_surface_area(l, w, h)
|
|
sum += get_slack_amount(l, w, h)
|
|
r_sum += get_ribbon_amount(l, w, h)
|
|
|
|
print(f'Part 1, sum of wrapping paper: {sum}')
|
|
print(f'Part 2, sum of ribbon: {r_sum}')
|
|
|
|
if __name__ == "__main__":
|
|
main()
|