From 8d43e37df99f280377bed90284d6ac2428334804 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Wed, 30 Nov 2022 19:55:31 -0500 Subject: move 2021 days to folder; update README --- day7/maxima.mac | 10 ---------- day7/part1.clj | 18 ------------------ day7/part2.clj | 20 -------------------- 3 files changed, 48 deletions(-) delete mode 100644 day7/maxima.mac delete mode 100644 day7/part1.clj delete mode 100644 day7/part2.clj (limited to 'day7') diff --git a/day7/maxima.mac b/day7/maxima.mac deleted file mode 100644 index a1c2d18..0000000 --- a/day7/maxima.mac +++ /dev/null @@ -1,10 +0,0 @@ -load("descriptive")$ -load("in.mac")$ /* Should define `input` list of numbers. */ - -calcfuel(pos, distmod) := - lreduce("+", map(lambda([n], distmod(abs(pos - n))), input))$ - -calcfuel(median(input), lambda([x],x)); -calcfuel(floor(mean(input)), lambda([x], (x*(x+1)/2))); -calcfuel(floor(mean(input)) + 1, lambda([x], (x*(x+1)/2))); - diff --git a/day7/part1.clj b/day7/part1.clj deleted file mode 100644 index f08e5b4..0000000 --- a/day7/part1.clj +++ /dev/null @@ -1,18 +0,0 @@ -(defn median [lst] - (as-> (count lst) $ - (quot $ 2) - (subvec (vec (sort lst)) (dec $) (inc $)) - (if (even? (count lst)) (apply + $) (second $)) - (quot $ 2) - ) - ) - -(as-> (slurp "./in") $ ; "16,1,2,0,4,2,7,1,2,14" - (clojure.string/split $ #",") - (mapv read-string $) - (map (partial - (median $)) $) - (map #(Math/abs %) $) - (apply + $) - (println $) - ) - diff --git a/day7/part2.clj b/day7/part2.clj deleted file mode 100644 index b96b55d..0000000 --- a/day7/part2.clj +++ /dev/null @@ -1,20 +0,0 @@ -(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)))) - ) - -- cgit v1.2.3