summary refs log tree commit diff stats
path: root/day2.py
blob: 853e507924e7128a0834d511151118528d36abe1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
from itertools import combinations
from math import prod

with open('day2.txt') as data:
    dims = [tuple(map(int, line.strip().split('x'))) for line in data]

# part 1
total_area = 0
for dim in dims:
    areas = combinations(dim, 2)
    areas = list(map(lambda x: prod(x), areas))
    total_area += 2 * sum(areas) + min(areas)

print(total_area)

# part 2
total_length = 0
for dim in dims:
    wrap = 2 * sum(sorted(dim)[:2])
    bow = prod(dim)
    total_length += wrap + bow
print(total_length)