Skip to content

Commit 55854a4

Browse files
committed
even more styling changes
1 parent 92abe83 commit 55854a4

13 files changed

+123
-123
lines changed

clojure/day05.clj

+4-5
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565

6666

6767
(defn part-1 [seeds maps]
68-
(->> (reduce convert-1 seeds maps)
69-
(reduce min)))
68+
(reduce min (reduce convert-1 seeds maps)))
7069

7170
(defn part-2 [seeds maps]
7271
(->> (reduce convert-2 seeds maps)
@@ -76,9 +75,9 @@
7675

7776
(defn solve [input]
7877
(let [[[seeds] & maps] (aoc/parse-input-paragraphs input)
79-
seeds-1 (aoc/integers seeds)
80-
seeds-2 (seed-ranges seeds-1)
81-
rules (map parse-maps maps)]
78+
seeds-1 (aoc/integers seeds)
79+
seeds-2 (seed-ranges seeds-1)
80+
rules (map parse-maps maps)]
8281
[(part-1 seeds-1 rules)
8382
(part-2 seeds-2 rules)]))
8483

clojure/day07.clj

+7-7
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515

1616
(defn parse-hand [jokers? [cards bid]]
17-
(let [cards' (change-cards-representation cards jokers?)
18-
jokers (aoc/count-if #{\0} cards')
17+
(let [cards' (change-cards-representation cards jokers?)
18+
jokers (aoc/count-if #{\0} cards')
1919
card-counts (->> (str/replace cards' "0" "")
2020
frequencies
2121
vals
2222
(sort >)
2323
vec)
24-
hand-type (match card-counts
25-
[] [jokers 0]
26-
[x] [(+ jokers x) 0]
27-
[x y & _] [(+ jokers x) y])]
24+
hand-type (match card-counts
25+
[] [jokers 0]
26+
[x] [(+ jokers x) 0]
27+
[x y & _] [(+ jokers x) y])]
2828
[hand-type cards' (parse-long bid)]))
2929

3030

@@ -38,7 +38,7 @@
3838

3939
(defn total-winnings [hands jokers?]
4040
(->> hands
41-
(map (partial parse-hand jokers?))
41+
(map #(parse-hand jokers? %))
4242
sort
4343
(into [[0 "" 0]]) ; to have ranks start at 1
4444
calc-score))

clojure/day08.clj

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121

2222
(defn ghost-steps [instrs network starts]
2323
(transduce
24-
(map (partial steps instrs network))
24+
(map #(steps instrs network %))
2525
aoc/lcm
2626
starts))
2727

2828

2929
(defn solve [input]
3030
(let [[[instrs'] network'] (aoc/parse-input-paragraphs input)
3131
network (parse-network network')
32-
instrs (mapv (comp keyword str) instrs')
33-
starts (filter #(str/ends-with? % "A") (keys network))]
32+
instrs (mapv (comp keyword str) instrs')
33+
starts (filter #(str/ends-with? % "A") (keys network))]
3434
[(steps instrs network :AAA)
3535
(ghost-steps instrs network starts)]))
3636

clojure/day10.clj

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
(defn traverse [sketch start]
1010
(loop [[x y :as curr] (aoc/pt+ start [0 1])
11-
[px py] start
12-
seen (transient #{})
11+
[px py] start
12+
seen (transient #{})
1313
verticals (transient {})]
1414
(let [seen' (conj! seen curr)
1515
dx (- x px)
@@ -32,22 +32,22 @@
3232
curr seen' verticals)))))
3333

3434
(defn enclosed [seen verticals h w]
35-
(for [y (range h)
36-
:let [row-verts (verticals y)]
35+
(for [y (range h)
36+
:let [row-verts (verticals y)]
3737
:when row-verts
38-
:let [min-vert (reduce min row-verts)
38+
:let [min-vert (reduce min row-verts)
3939
max-vert (reduce max row-verts)]
40-
x (range w)
40+
x (range w)
4141
:when (and (< min-vert x max-vert)
4242
(not (seen [x y]))
4343
(odd? (aoc/count-if #(< % x) row-verts)))]
4444
1))
4545

4646
(defn solve [input]
4747
(let [sketch (aoc/parse-input input :chars)
48-
start (find-start sketch)
49-
h (count sketch)
50-
w (count (first sketch))
48+
start (find-start sketch)
49+
h (count sketch)
50+
w (count (first sketch))
5151
{:keys [pipes verts]} (traverse sketch start)]
5252
[(/ (count pipes) 2)
5353
(count (enclosed pipes verts h w))]))

clojure/day11.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
(defn find-galaxies [lines]
99
(for [[y line] (map-indexed vector lines)
10-
[x chr] (map-indexed vector line)
11-
:when (= chr \#)]
10+
[x chr] (map-indexed vector line)
11+
:when (= chr \#)]
1212
[x y]))
1313

1414

@@ -25,7 +25,7 @@
2525
(-> acc
2626
(update :sum + (* coeff coord))
2727
(update :coeff + 2)))
28-
{:sum 0
28+
{:sum 0
2929
:coeff (- 1 (count galaxies))})
3030
:sum))
3131

@@ -35,7 +35,7 @@
3535
(reduce
3636
(fn [acc coord]
3737
(let [before (count (take-while #(< % coord) galaxies))
38-
after (- total before)]
38+
after (- total before)]
3939
(+ acc (* before after))))
4040
0
4141
empties)))

clojure/day12.clj

+7-7
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@
2828
(if (empty? groups)
2929
(if (every? is-operational? pattern) 1 0)
3030
(let [[size & tl] groups
31-
post (+ (reduce + tl) (count tl))
32-
score (atom 0)]
33-
(doseq [pre (range (inc (- (count pattern) post size)))
34-
:let [[before pattern'] (split-at pre pattern)
35-
[current remaining] (split-at size pattern')]
31+
post (+ (reduce + tl) (count tl))
32+
score (atom 0)]
33+
(doseq [pre (range (inc (- (count pattern) post size)))
34+
:let [[before pattern'] (split-at pre pattern)
35+
[current remaining] (split-at size pattern')]
3636
:while (every? is-operational? before)
37-
:when (every? is-damaged? current)]
37+
:when (every? is-damaged? current)]
3838
(cond
3939
(empty? tl) (when (every? is-operational? remaining)
4040
(swap! score inc))
@@ -45,7 +45,7 @@
4545

4646

4747
(defn solve [input]
48-
(let [lines (aoc/parse-input input parse-line)
48+
(let [lines (aoc/parse-input input parse-line)
4949
unfolded (map unfold lines)]
5050
[(reduce + (map arrangements lines))
5151
(reduce + (pmap arrangements unfolded))]))

clojure/day13.clj

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@
88

99
(defn mirror? [part pattern nrettap line]
1010
(let [before (take-last line nrettap)
11-
after (drop line pattern)
12-
diffs (map differences before after)]
11+
after (drop line pattern)
12+
diffs (map differences before after)]
1313
(case part
1414
1 (every? zero? diffs)
1515
2 (= 1 (reduce + diffs)))))
1616

1717

1818
(defn mirror-line [part pattern]
1919
(aoc/find-first
20-
(partial mirror? part pattern (rseq pattern))
20+
#(mirror? part pattern (rseq pattern) %)
2121
(range 1 (count pattern))))
2222

2323

@@ -28,7 +28,7 @@
2828

2929

3030
(defn notes-sum [patterns part]
31-
(reduce + (pmap (partial find-mirror part) patterns)))
31+
(reduce + (pmap #(find-mirror part %) patterns)))
3232

3333

3434
(defn solve [input]

clojure/day14.clj

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
(->> (str/split line #"#" -1)
1414
(map (comp str/join
1515
(case dir
16-
:left reverse
16+
:left reverse
1717
:right identity)
1818
sort))
1919
(str/join "#")))
2020

2121

2222
(defn move-east [platform]
23-
(pmap (partial move-line :right) platform))
23+
(pmap #(move-line :right %) platform))
2424

2525
(defn move-west [platform]
26-
(pmap (partial move-line :left) platform))
26+
(pmap #(move-line :left %) platform))
2727

2828
(defn move-north [platform]
2929
(-> platform rotate move-west rotate))
@@ -37,7 +37,7 @@
3737

3838
(defn calc-score [platform]
3939
(let [platform (vec platform)
40-
size (count platform)]
40+
size (count platform)]
4141
(reduce
4242
(fn [acc n]
4343
(+ acc (* (- size n)
@@ -47,8 +47,8 @@
4747

4848

4949
(defn remaining-shakes [platform prev curr]
50-
(let [r (- 1000000000 prev)
51-
to-spin (mod r (- curr prev))]
50+
(let [remain (- 1000000000 prev)
51+
to-spin (mod remain (- curr prev))]
5252
(nth (iterate spin-cycle platform) to-spin)))
5353

5454

clojure/day15.clj

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737

3838

3939
(defn focusing-power [boxes]
40-
(reduce + (for [[i box] (map-indexed vector boxes)
40+
(reduce + (for [[i box] (map-indexed vector boxes)
4141
[j [_ focal]] (map-indexed vector box)]
4242
(* (inc i) (inc j) focal))))
4343

4444

4545
(defn solve [input]
46-
(let [steps (aoc/parse-input-line input :words #",")
46+
(let [steps (aoc/parse-input-line input :words #",")
4747
instructions (map parse-instruction steps)]
4848
[(reduce + (map word-hash steps))
4949
(focusing-power (hashmap instructions))]))

clojure/day17.clj

+24-26
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,34 @@
1111

1212

1313
(defn traverse [city min-straight max-straight]
14-
(let [size (count city)
15-
end (dec size)
14+
(let [size (count city)
15+
end (dec size)
1616
queue (priority-map [0 0 1 0] 0
1717
[0 0 0 1] 0)]
18-
(loop [seen #{}
18+
(loop [seen #{}
1919
queue queue]
2020
(let [[[x y dx dy :as state] heat] (peek queue)
21-
queue' (pop queue)]
22-
(if (= end x y)
23-
heat
24-
(if (seen state)
25-
(recur seen queue')
26-
(recur
27-
(conj seen state)
28-
(reduce
29-
(fn [q [dx' dy']]
30-
(reduce
31-
(fn [q n]
32-
(let [nx (+ x (* n dx'))
33-
ny (+ y (* n dy'))]
34-
(if-not (aoc/inside? size nx ny)
35-
(reduced q)
36-
(let [heat' (+ heat (heat-loss city x y dx' dy' n))
37-
state' [nx ny dx' dy']]
38-
(assoc q state' (min heat' (q state' Integer/MAX_VALUE)))))))
39-
q
40-
(range min-straight (inc max-straight))))
41-
queue'
42-
[[(- dy) dx]
43-
[dy (- dx)]]))))))))
21+
queue' (pop queue)]
22+
(cond
23+
(= end x y) heat
24+
(seen state) (recur seen queue')
25+
:else (recur
26+
(conj seen state)
27+
(reduce
28+
(fn [q [dx' dy']]
29+
(reduce (fn [q n]
30+
(let [nx (+ x (* n dx'))
31+
ny (+ y (* n dy'))]
32+
(if-not (aoc/inside? size nx ny)
33+
(reduced q)
34+
(let [heat' (+ heat (heat-loss city x y dx' dy' n))
35+
state' [nx ny dx' dy']]
36+
(assoc q state' (min heat' (q state' Integer/MAX_VALUE)))))))
37+
q
38+
(range min-straight (inc max-straight))))
39+
queue'
40+
[[(- dy) dx]
41+
[dy (- dx)]])))))))
4442

4543

4644
(defn solve [input]

clojure/day18.clj

+8-8
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,28 @@
88

99

1010
(defn parse-line [line]
11-
(let [[d n c] (str/split line #" ")
12-
c (str/replace c #"[(#)]" "")
11+
(let [[d n c] (str/split line #" ")
12+
c (str/replace c #"[(#)]" "")
1313
[dist dir] (map str/join (split-at 5 c))
14-
dist (Integer/parseInt dist 16)]
14+
dist (Integer/parseInt dist 16)]
1515
{:p1 {:dir (deltas d)
1616
:dist (parse-long n)}
1717
:p2 {:dir (deltas dir)
1818
:dist dist}}))
1919

2020

2121
(defn dig-trench [input]
22-
; Shoelace formula + Pick's theorem
22+
;; Shoelace formula + Pick's theorem
2323
(->> input
2424
(reduce (fn [{:keys [total x]}
2525
{:keys [dir dist]}]
2626
(let [[dx dy] dir
27-
nx (+ x (* dist dx))
28-
area (* nx dist dy)]
29-
{:x nx
27+
nx (+ x (* dist dx))
28+
area (* nx dist dy)]
29+
{:x nx
3030
:total (+ total area (/ dist 2))}))
3131
{:total 1
32-
:x 0})
32+
:x 0})
3333
:total
3434
long))
3535

clojure/day19.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
workflows (into {} (map parse-workflow wrkfls))
7373
ratings (map parse-rating rtngs)
7474
rating-2 (zipmap [:x :m :a :s] (repeat [1 4000]))]
75-
[(reduce + (map (partial accepted workflows) ratings))
75+
[(reduce + (map #(accepted workflows %) ratings))
7676
(accepted-combinations workflows rating-2)]))
7777

7878

0 commit comments

Comments
 (0)