aboutsummaryrefslogtreecommitdiffstats
path: root/day7/part2.clj
diff options
context:
space:
mode:
Diffstat (limited to 'day7/part2.clj')
-rw-r--r--day7/part2.clj23
1 files changed, 23 insertions, 0 deletions
diff --git a/day7/part2.clj b/day7/part2.clj
new file mode 100644
index 0000000..c051a6a
--- /dev/null
+++ b/day7/part2.clj
@@ -0,0 +1,23 @@
+(def input
+ (->> (slurp "./in") ;"16,1,2,0,4,2,7,1,2,14"
+ (#(clojure.string/split % #","))
+ (map read-string)
+ )
+ )
+
+(defn mean [lst]
+ (quot (apply + lst) (count lst))
+ )
+
+(defn calc-fuel [lst meen]
+ (->> input
+ (map (partial - meen))
+ (map #(if (neg? %) (- %) %))
+ (map #(apply + (range 1 (inc %))))
+ (apply +)
+ )
+ )
+
+(println (min (calc-fuel input (mean input))
+ (calc-fuel input (inc (mean input)))))
+