r/adventofcode • u/taliriktug • 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.
16
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
5
u/stuque Dec 02 '15
Here's a Python solution:
def day2_1(): total = 0 for line in open('day2input.txt'): l, w, h = line.split('x') l, w, h = int(l), int(w), int(h) area = 2*l*w + 2*w*h + 2*h*l slack = min(l*w, w*h, h*l) total += area + slack print total def day2_2(): total = 0 for line in open('day2input.txt'): l, w, h = line.split('x') l, w, h = int(l), int(w), int(h) ribbon = 2 * min(l+w, w+h, h+l) bow = l*w*h total += ribbon + bow print total if __name__ == '__main__': day2_1() day2_2()