init day 11

This commit is contained in:
Adam Jeniski 2024-12-11 15:15:12 -05:00
parent ecb315549f
commit 58bc591ae9
2 changed files with 48 additions and 0 deletions

1
2024/input/11.txt Normal file
View File

@ -0,0 +1 @@
5178527 8525 22 376299 3 69312 0 275

47
2024/src/day11.clj Normal file
View File

@ -0,0 +1,47 @@
(ns day11
(:require
[clojure.string :as str]
[core :as c]
[input-manager]))
(def input (->> (input-manager/get-input 11)
first
c/split-whitespace
(map parse-long)
frequencies))
(defn split-num [n]
(let [s (str n)
m (count s)]
(map parse-long (map str/join (split-at (int (/ m 2)) s)))))
(defn incr-count [coll k amnt]
(update coll k #(if (nil? %)
amnt
(+ % amnt))))
(defn update-counts [cnts]
(reduce
(fn [cnts' n]
(let [cnt (cnts n)]
(cond
(= 0 n) (incr-count cnts' 1 cnt)
(even? (count (str n)))
(let [[a b] (split-num n)]
(-> (incr-count cnts' a cnt)
(incr-count b cnt)))
:else (incr-count cnts' (* n 2024) cnt))))
{}
(keys cnts)))
(defn ans [n]
(->> (range n)
(reduce (fn [acc _] (update-counts acc))
input)
(map second)
(reduce +)))
(ans 25)
(ans 75)