aboutsummaryrefslogtreecommitdiffstats
path: root/day7
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 /day7
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day7')
-rw-r--r--day7/maxima.mac10
-rw-r--r--day7/part1.clj18
-rw-r--r--day7/part2.clj20
3 files changed, 0 insertions, 48 deletions
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))))
- )
-