Skip to content

Commit c7411eb

Browse files
committedDec 11, 2024··
refaktor d11
1 parent ce1de6a commit c7411eb

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed
 

‎notebooks/y2024/d11.clj

+2-5
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,9 @@
7070
; I stedet for rekursiv memoisering kan vi bruke en hashmap for å "deduplisere"
7171
; like tall underveis, og holde telling på antallet like tall.
7272

73-
(set! *warn-on-reflection* true)
74-
(set! *unchecked-math* :warn-on-boxed)
75-
7673
(defn solve-iteration [freqs]
7774
(reduce-kv (fn [acc ^long k v]
78-
(let [update-add (fn [c] (+ (or c 0) v))]
75+
(let [update-add (fnil #(+ v %) 0)]
7976
(cond
8077
(zero? k) (update acc 1 update-add)
8178
(-> k digits even?) (let [[n1 n2] (split-number k)]
@@ -89,7 +86,7 @@
8986
(let [numbers (map parse-long (re-seq #"\d+" input))
9087
num-freqs (frequencies numbers)]
9188
(->> (nth (iterate solve-iteration num-freqs) n)
92-
vals (reduce +))))
89+
(transduce (map second) +))))
9390

9491
(solve-freq 25 test-input)
9592

0 commit comments

Comments
 (0)
Please sign in to comment.