aboutsummaryrefslogtreecommitdiff
path: root/2024/01/solve.py
diff options
context:
space:
mode:
authorMarvin Borner2024-12-01 06:06:39 +0100
committerMarvin Borner2024-12-01 06:07:59 +0100
commit4f30d2364bb34c320e2e0be85eee64c2615db6de (patch)
tree26f8f03d0634a5e77f0787f72a948b3291c9de28 /2024/01/solve.py
parentddf5eb648c83313bd6550ad8df0c93ee1b1fbd19 (diff)
Aah almost sub 3, anyway good night see you in 6h
Diffstat (limited to '2024/01/solve.py')
-rwxr-xr-x2024/01/solve.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/2024/01/solve.py b/2024/01/solve.py
new file mode 100755
index 0000000..e0c8ab0
--- /dev/null
+++ b/2024/01/solve.py
@@ -0,0 +1,33 @@
+#!/bin/env python
+
+# L = open("input").readlines()
+L = [
+ [int(i) for i in l.strip().split(" ")] for l in open("input").readlines()
+]
+# L = [int(l.strip()) for l in open("input").readlines()]
+
+
+def part1():
+ res = 0
+ left = [l[0] for l in L]
+ right = [l[1] for l in L]
+ while left:
+ left_min = min(range(len(left)), key=left.__getitem__)
+ right_min = min(range(len(right)), key=right.__getitem__)
+ res += abs(left[left_min] - right[right_min])
+ del left[left_min]
+ del right[right_min]
+ print(res)
+
+
+def part2():
+ res = 0
+ left = [l[0] for l in L]
+ right = [l[1] for l in L]
+ for i, l in enumerate(left):
+ res += l * right.count(l)
+ print(res)
+
+
+part1()
+part2()