Skip to content

Instantly share code, notes, and snippets.

@agentultra
Created December 14, 2015 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agentultra/6384bc3af2b0f38b3074 to your computer and use it in GitHub Desktop.
Save agentultra/6384bc3af2b0f38b3074 to your computer and use it in GitHub Desktop.
import sys
from collections import namedtuple
RightRectPrism = namedtuple('RightRectPrism', ('l', 'w', 'h'))
def parse_prism(s):
return RightRectPrism(*map(int, s.strip().split('x')))
def wrapping_area(prism):
sides = [prism.l * prism.w,
prism.w * prism.h,
prism.h * prism.l]
smallest = min(sides)
return sum(map(lambda x: 2 * x, sides)) + smallest
def main(args=()):
total = 0
with open('2-1.txt') as f:
for line in f.readlines():
prism = parse_prism(line)
total += wrapping_area(prism)
print('They should order: %d' % total)
if __name__ == '__main__':
sys.exit(main(sys.argv))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment