We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent ce1de6a commit c7411ebCopy full SHA for c7411eb
notebooks/y2024/d11.clj
@@ -70,12 +70,9 @@
70
; I stedet for rekursiv memoisering kan vi bruke en hashmap for å "deduplisere"
71
; like tall underveis, og holde telling på antallet like tall.
72
73
-(set! *warn-on-reflection* true)
74
-(set! *unchecked-math* :warn-on-boxed)
75
-
76
(defn solve-iteration [freqs]
77
(reduce-kv (fn [acc ^long k v]
78
- (let [update-add (fn [c] (+ (or c 0) v))]
+ (let [update-add (fnil #(+ v %) 0)]
79
(cond
80
(zero? k) (update acc 1 update-add)
81
(-> k digits even?) (let [[n1 n2] (split-number k)]
@@ -89,7 +86,7 @@
89
86
(let [numbers (map parse-long (re-seq #"\d+" input))
90
87
num-freqs (frequencies numbers)]
91
88
(->> (nth (iterate solve-iteration num-freqs) n)
92
- vals (reduce +))))
+ (transduce (map second) +))))
93
94
(solve-freq 25 test-input)
95
0 commit comments