aboutsummaryrefslogtreecommitdiffstats
path: root/year2021/day7/part2.clj
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /year2021/day7/part2.clj
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'year2021/day7/part2.clj')
-rw-r--r--year2021/day7/part2.clj20
1 files changed, 20 insertions, 0 deletions
diff --git a/year2021/day7/part2.clj b/year2021/day7/part2.clj
new file mode 100644
index 0000000..b96b55d
--- /dev/null
+++ b/year2021/day7/part2.clj
@@ -0,0 +1,20 @@
+(defn calc-fuel [lst pos]
+ (reduce #(as-> %2 $
+ (- pos $)
+ (Math/abs $)
+ (/ (* $ (inc $)) 2)
+ (+ %1 $)
+ )
+ 0 lst
+ )
+ )
+
+(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))]
+ (println (min (calc-fuel input mean)
+ (calc-fuel input (inc mean))))
+ )
+