diff --git a/clojure/day03.clj b/clojure/day03.clj index e36a372..e813f70 100644 --- a/clojure/day03.clj +++ b/clojure/day03.clj @@ -11,7 +11,7 @@ (defn gear-ratios [gear-values] (keep - #(when (= (count %) 2) + #(when (= 2 (count %)) (reduce * %)) gear-values)) diff --git a/clojure/day04.clj b/clojure/day04.clj index 117b305..76611e4 100644 --- a/clojure/day04.clj +++ b/clojure/day04.clj @@ -23,9 +23,9 @@ (fn [amounts line] (let [copies (amounts line)] (reduce (fn [amounts delta] - (update amounts (+ line delta 1) + copies)) + (update amounts (+ line delta) + copies)) amounts - (range (winners line))))) + (range 1 (inc (winners line)))))) (vec (repeat size 1)) (range size)))) diff --git a/clojure/day05.clj b/clojure/day05.clj index 24457d9..6e62d0e 100644 --- a/clojure/day05.clj +++ b/clojure/day05.clj @@ -3,9 +3,9 @@ (defn parse-line [line] - (let [[dest src rng] (aoc/integers line)] + (let [[dest src len] (aoc/integers line)] {:lo src - :hi (+ src (dec rng)) + :hi (+ src (dec len)) :diff (- dest src)})) (defn parse-maps [maps] @@ -14,10 +14,11 @@ (sort-by :lo))) (defn seed-ranges [seeds] - (->> (for [[st rng] (partition 2 seeds)] - {:start st - :stop (+ st (dec rng))}) - (sort-by :start))) + (sort-by + :start + (for [[start len] (partition 2 seeds)] + {:start start + :stop (+ start (dec len))}))) (defn convert-number [rules src] diff --git a/clojure/day06.clj b/clojure/day06.clj index 94cd37d..7c11aaf 100644 --- a/clojure/day06.clj +++ b/clojure/day06.clj @@ -19,11 +19,9 @@ (defn solve [input] - (let [[times distances] (aoc/parse-input input :ints) - time-2 (fix-keming times) - distance-2 (fix-keming distances)] - [(transduce (map find-winners) * (zipmap times distances)) - (find-winners [time-2 distance-2])])) + (let [document (aoc/parse-input input :ints)] + [(transduce (map find-winners) * (aoc/transpose document)) + (find-winners (mapv fix-keming document))])) (solve (aoc/read-file 6)) diff --git a/clojure/day11.clj b/clojure/day11.clj index 2556c04..f9f98de 100644 --- a/clojure/day11.clj +++ b/clojure/day11.clj @@ -42,14 +42,14 @@ (defn solve [input] - (let [lines (aoc/parse-input input) - galaxies (find-galaxies lines) + (let [lines (aoc/parse-input input) + galaxies (find-galaxies lines) galaxies-x (sort (map first galaxies)) galaxies-y (sort (map second galaxies)) empty-rows (empty-lines lines) empty-cols (empty-lines (aoc/transpose lines)) - distances (+ (calc-dist galaxies-x) - (calc-dist galaxies-y)) + distances (+ (calc-dist galaxies-x) + (calc-dist galaxies-y)) expansions (+ (expansion galaxies-x empty-cols) (expansion galaxies-y empty-rows))] [(+ distances expansions) diff --git a/clojure/day13.clj b/clojure/day13.clj index ba66133..fd677c7 100644 --- a/clojure/day13.clj +++ b/clojure/day13.clj @@ -6,7 +6,7 @@ (aoc/count-if false? (map = a b))) -(defn is-mirror? [part pattern nrettap line] +(defn mirror? [part pattern nrettap line] (let [before (take-last line nrettap) after (drop line pattern) diffs (map differences before after)] @@ -17,7 +17,7 @@ (defn mirror-line [part pattern] (aoc/find-first - (partial is-mirror? part pattern (rseq pattern)) + (partial mirror? part pattern (rseq pattern)) (range 1 (count pattern)))) diff --git a/deps.edn b/deps.edn index cc0ef7f..73934ab 100644 --- a/deps.edn +++ b/deps.edn @@ -4,10 +4,13 @@ org.clojure/data.int-map {:mvn/version "1.2.1"} org.clojure/core.async {:mvn/version "1.6.681"} org.flatland/ordered {:mvn/version "1.15.11"} - org.clojure/data.priority-map {:mvn/version "1.1.0"}} + org.clojure/data.priority-map {:mvn/version "1.1.0"} + io.github.engelberg/better-cond {:git/tag "v2.1.5" :git/sha "156bc5f"}} :aliases {:profile {:jvm-opts ["-Djdk.attach.allowAttachSelf"] :extra-deps {criterium/criterium {:mvn/version "0.4.6"} com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.1.0"} com.taoensso/tufte {:mvn/version "2.6.3"}}} - :viz {:extra-deps {quil/quil {:mvn/version "4.3.1323"}}}}} + :viz {:extra-deps {quil/quil {:mvn/version "4.3.1323"}}} + :splint {:extra-deps {io.github.noahtheduke/splint {:mvn/version "1.15.0"}} + :main-opts ["-m" "noahtheduke.splint"]}}}