aboutsummaryrefslogtreecommitdiffstats
path: root/day7/part2.clj
blob: c051a6a350ff437a96b514bec3445371b975a574 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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)))))