From 58bc591ae9c0f828b9fe8c623c2a2a5eba9496c8 Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Wed, 11 Dec 2024 15:15:12 -0500 Subject: [PATCH] init day 11 --- 2024/input/11.txt | 1 + 2024/src/day11.clj | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 2024/input/11.txt create mode 100644 2024/src/day11.clj diff --git a/2024/input/11.txt b/2024/input/11.txt new file mode 100644 index 0000000..87f9c0f --- /dev/null +++ b/2024/input/11.txt @@ -0,0 +1 @@ +5178527 8525 22 376299 3 69312 0 275 diff --git a/2024/src/day11.clj b/2024/src/day11.clj new file mode 100644 index 0000000..48f9707 --- /dev/null +++ b/2024/src/day11.clj @@ -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)