Created
December 14, 2015 21:42
-
-
Save agentultra/6384bc3af2b0f38b3074 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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