summary refs log tree commit diff stats
path: root/day2.py
diff options
context:
space:
mode:
Diffstat (limited to 'day2.py')
-rw-r--r--day2.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/day2.py b/day2.py
new file mode 100644
index 0000000..853e507
--- /dev/null
+++ b/day2.py
@@ -0,0 +1,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)