Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. def much_wrapping_paper(l, w, h):
  2. r = 2 * l * w + 2 * w * h + 2 * h * l
  3. return r + min(l * w, w * h, h * l)
  4.  
  5. def much_ribbon(l, w, h):
  6. a, b = sorted((l, w, h))[:2]
  7. return 2 * a + 2 * b + l * w * h
  8.  
  9. if __name__ == '__main__':
  10. from re import match
  11.  
  12. with open('./input') as f:
  13. lines = f.read().strip().split('\n')
  14.  
  15. res = []
  16.  
  17. for l in lines:
  18. gdict = match('(?P<l>\d+)x(?P<w>\d+)x(?P<h>\d+)', l).groupdict()
  19. l, w, h = map(int, (gdict['l'], gdict['w'], gdict['h']))
  20. #res.append(much_wrapping_paper(l, w, h))
  21. res.append(much_ribbon(l, w, h))
  22.  
  23. r = sum(res)
  24. print('*** Answer2={}'.format(r))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement