""" stringcomprehension: get cuboid dimension and sum all surface aera plus again the smallest sides """ def surface(dimensions:str) -> int: l,w,h = [int(i) for i in dimensions.strip().split('x')] s1, s2, s3 = l*w,w*h,h*l return 2*(s1+s2+s3)+min([s1,s2,s3]) with open('dimensions.txt') as filein: lines = filein.readlines() # print([surface(line) for line in ["2x3x4","1x1x10"]]) print(sum([surface(line) for line in lines])) """ now get the smallest circumference and add the volume """ import numpy as np def ribbon(dimensions:str): l,w,h = [int(i) for i in dimensions.strip().split('x')] perimiter = min(np.array([l+w,w+h,h+l])*2) return perimiter + l*w*h print(sum([ribbon(line) for line in lines]))