Skip to content

Instantly share code, notes, and snippets.

@DeLaGuardo
Created December 11, 2024 13:14
Show Gist options
  • Save DeLaGuardo/830af058cc038e7688317d96e1bcfac1 to your computer and use it in GitHub Desktop.
Save DeLaGuardo/830af058cc038e7688317d96e1bcfac1 to your computer and use it in GitHub Desktop.
aoc24_d11
(require '[clojure.string :as string])
(def blink
(memoize
(fn [times n]
(if (zero? times)
1
(let [l (count n)
l-half (bit-shift-right l 1)
even? (= (+ l-half l-half) l)]
(cond
(= n "0")
(blink (dec times) "1")
even?
(let [sl (subs n 0 l-half)
sr (string/replace-first (subs n l-half) #"^0+" "")
sr (if (zero? (count sr)) "0" sr)]
(+ (blink (dec times) sl)
(blink (dec times) sr)))
:else
(blink (dec times) (str (*' (parse-long n) 2024)))))))))
(defn solve [times numbers]
(transduce
(comp (map str)
(map #(blink times %)))
+
numbers))
(comment
(time
(dotimes [_ 100000]
(solve 25 '(125 17))))
(time
(dotimes [_ 100000]
(solve 75 '(64599 31 674832 2659361 1 0 8867 321)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment