summaryrefslogtreecommitdiff
path: root/7_2021.py
diff options
context:
space:
mode:
authorJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
committerJack Sangdahl <[email protected]>2024-06-15 22:20:32 -0600
commit8e313e2614c7a0fe5af924febdbacc650e33835e (patch)
tree63426b6942ceebe17708140c972a7d7451bd2f74 /7_2021.py
downloadaoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz
aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip
intial
Diffstat (limited to '7_2021.py')
-rw-r--r--7_2021.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/7_2021.py b/7_2021.py
new file mode 100644
index 0000000..9c38a76
--- /dev/null
+++ b/7_2021.py
@@ -0,0 +1,23 @@
+import sys
+
+data = sys.argv[1] if len(sys.argv) > 1 else "../day7data.txt"
+X = [int(x) for x in open(data).read().strip().split(",")]
+
+X.sort()
+T = X[len(X) // 2]
+ans = 0
+
+
+def C2(d):
+ return d * (d + 1) / 2
+
+
+best = 1e9
+for med in range(2000):
+ score = 0
+ for x in X:
+ d = abs(x - med)
+ score += C2(d)
+ if score < best:
+ best = score
+print(best)