You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
506 B
Clojure

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