r/adventofcode • • Dec 02 '15

Spoilers Day 2 solutions

Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.

15 Upvotes

161 comments sorted by

View all comments

Show parent comment

1

u/larivact Dec 02 '15 edited Dec 02 '15

I like your code. Here's mine:

wrappingPaperNeeded = 0
ribbonNeeded = 0

for line in open('day2.txt'):
    args = line.split('x')
    length, width, height = int(args[0]), int(args[1]), int(args[2])

    #Part 1
    sideAreas = [width*length, width*height, length*height]
    wrappingPaperNeeded += 2 * sum(sideAreas) + min(sideAreas)

    #Part 2
    volume = length * width * height
    ribbonNeeded += 2 * min(width+length, width+height, length+height) + volume

print "\nBuying list"
print "-----------"
print "Square feets of wrapping paper:",wrappingPaperNeeded
print "Feets of ribbon needed:",ribbonNeeded

1

u/[deleted] Dec 02 '15 edited Sep 25 '16

the stormlight in this thread has faded

2

u/larivact Dec 02 '15

That's probably because there is a " missing at the end.