Frans Bergman 3 years ago
parent
commit
21de83c492
3 changed files with 19 additions and 0 deletions
  1. 0 0
      7.input
  2. 18 0
      7.py
  3. 1 0
      7.small.input

File diff suppressed because it is too large
+ 0 - 0
7.input


+ 18 - 0
7.py

@@ -0,0 +1,18 @@
+import statistics
+from util import get_input
+
+input = get_input("7.input")
+
+crabs = [int(a) for a in input[0].split(",")]
+
+median = statistics.median(crabs)
+
+print(sum([abs(a - median) for a in crabs]))
+
+maxpos = max(crabs)
+
+def movecost(a, b):
+    n = abs(a - b)
+    return (n * (n + 1)) / 2
+
+print(min([sum([movecost(a, target) for a in crabs]) for target in range(maxpos + 1)]))

+ 1 - 0
7.small.input

@@ -0,0 +1 @@
+16,1,2,0,4,2,7,1,2,14

Some files were not shown because too many files changed in this diff