From 803b9b677fcfc9ca38e1231fcf5def0f35782936 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Tue, 7 Dec 2021 09:24:24 -0500 Subject: [PATCH] day7: learn as-> --- day7/part2.clj | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/day7/part2.clj b/day7/part2.clj index 83d2033..b96b55d 100644 --- a/day7/part2.clj +++ b/day7/part2.clj @@ -1,22 +1,19 @@ (defn calc-fuel [lst pos] - (->> lst - (map - (comp - #(/ (* % (inc %)) 2) - #(Math/abs %) - (partial - pos) - ) - ) - (apply +) - ) + (reduce #(as-> %2 $ + (- pos $) + (Math/abs $) + (/ (* $ (inc $)) 2) + (+ %1 $) + ) + 0 lst + ) ) -(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)) - ] +(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)))) )