From 8695b8b375e726295b5c2a8ac373df8b8b684b1d Mon Sep 17 00:00:00 2001 From: Aleh Suprunovich Date: Thu, 12 Dec 2024 21:26:10 +0300 Subject: [PATCH] day 11 part 1 --- src/day11.clj | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/day11.clj diff --git a/src/day11.clj b/src/day11.clj new file mode 100644 index 0000000..1cbdb38 --- /dev/null +++ b/src/day11.clj @@ -0,0 +1,41 @@ +(ns day11 + (:require [clojure.string :as string] + [helpers :refer [get-input]])) + +(def stones + (string/split + ;;"125 17" + (string/trim (get-input 11)) + #" ")) + +(defn split-stone [stone] + (let [ss (split-at + (/ (count stone) 2) + stone) + seq->stone + (fn [s] + (str + (parse-long + (apply str s))))] + (mapv seq->stone ss))) + +(defn blink [stone] + (cond + (= stone "0") + ["1"] + (even? (count stone)) + (split-stone stone) + :else + (vector + (str + (* 2024 + (parse-long stone)))))) + +(time + (println "I blinked 25 times, there's" + (count + (loop [i 0 stones stones] + (if (= 25 i) + stones + (recur (inc i) (mapcat blink stones))))) + "stones!"))