with open('data-2015-02.txt', 'r') as f:
pres = f.read().splitlines()Advent of Code 2015 Day 2
— Day 2: I Was Told There Would Be No Math —
The elves need to order some wrapping paper, luckily they are all cube-ish.
All numbers in the elves’ list are in feet. How many total square feet of wrapping paper should they order?
Split into separate pieces for the different dimensions - try lists first? Do some calculations - we need area, minimum area, and then sum
pres_dim = [[int(y) for y in p.split('x')] for p in pres]
for y in pres_dim:
y.append(2 * y[0] * y[1])
y.append(2 * y[1] * y[2])
y.append(2 * y[0] * y[2])
y.append(min(y[3], y[4], y[5])/2)
y.append(y[3] + y[4] + y[5] + y[6])Now to do a sum of the last elements of the lists
sum(x[7] for x in pres_dim)
# 15863001586300.0
— Part Two —
We also need some ribbon for the presents!
How many total feet of ribbon should they order?
pres_dim = [[int(y) for y in p.split('x')] for p in pres]
for y in pres_dim:
y.append(2 * y[0] + 2 * y[1])
y.append(2 * y[1] + 2 * y[2])
y.append(2 * y[0] + 2 * y[2])
y.append(min(y[3], y[4], y[5]))
y.append(y[0] * y[1] * y[2])
y.append(y[6] + y[7]) And sum up the ribbon lengths :)
sum(x[8] for x in pres_dim)
# 37374983737498