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.

24 lines
472 B
Clojure

(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)))))