Skip to content

Commit

Permalink
some style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
narimiran committed May 11, 2024
1 parent 150bd29 commit 92abe83
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion clojure/day03.clj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

(defn gear-ratios [gear-values]
(keep
#(when (= (count %) 2)
#(when (= 2 (count %))
(reduce * %))
gear-values))

Expand Down
4 changes: 2 additions & 2 deletions clojure/day04.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

Expand Down
13 changes: 7 additions & 6 deletions clojure/day05.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
8 changes: 3 additions & 5 deletions clojure/day06.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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))
8 changes: 4 additions & 4 deletions clojure/day11.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions clojure/day13.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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))))


Expand Down
7 changes: 5 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}}}

0 comments on commit 92abe83

Please sign in to comment.