aboutsummaryrefslogtreecommitdiffstats
path: root/day7/part2.clj
blob: 83d20333271cfbb6fa88a369c8fffeb8a0ec1b1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
(defn calc-fuel [lst pos]
  (->> lst
       (map
         (comp
           #(/ (* % (inc %)) 2)
           #(Math/abs %)
           (partial - pos)
           )
         )
       (apply +)
       )
  )

(let [input (->> (slurp "./in") ;"16,1,2,0,4,2,7,1,2,14"
                 (#(clojure.string/split % #","))
                 (map read-string)
                 )
      mean (quot (apply + input) (count input))
      ]
  (println (min (calc-fuel input mean)
                (calc-fuel input (inc mean))))
  )