|
|
@ -1,22 +1,19 @@
|
|
|
|
(defn calc-fuel [lst pos]
|
|
|
|
(defn calc-fuel [lst pos]
|
|
|
|
(->> lst
|
|
|
|
(reduce #(as-> %2 $
|
|
|
|
(map
|
|
|
|
(- pos $)
|
|
|
|
(comp
|
|
|
|
(Math/abs $)
|
|
|
|
#(/ (* % (inc %)) 2)
|
|
|
|
(/ (* $ (inc $)) 2)
|
|
|
|
#(Math/abs %)
|
|
|
|
(+ %1 $)
|
|
|
|
(partial - pos)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
0 lst
|
|
|
|
)
|
|
|
|
)
|
|
|
|
(apply +)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
(let [input (->> (slurp "./in") ;"16,1,2,0,4,2,7,1,2,14"
|
|
|
|
(let [input (as-> (slurp "./in") $ ;"16,1,2,0,4,2,7,1,2,14"
|
|
|
|
(#(clojure.string/split % #","))
|
|
|
|
(clojure.string/split $ #",")
|
|
|
|
(map read-string)
|
|
|
|
(map read-string $)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
mean (quot (apply + input) (count input))
|
|
|
|
mean (quot (apply + input) (count input))]
|
|
|
|
]
|
|
|
|
|
|
|
|
(println (min (calc-fuel input mean)
|
|
|
|
(println (min (calc-fuel input mean)
|
|
|
|
(calc-fuel input (inc mean))))
|
|
|
|
(calc-fuel input (inc mean))))
|
|
|
|
)
|
|
|
|
)
|
|
|
|