mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 05:23:17 -09:00
init day 11
This commit is contained in:
parent
ecb315549f
commit
58bc591ae9
1
2024/input/11.txt
Normal file
1
2024/input/11.txt
Normal file
@ -0,0 +1 @@
|
||||
5178527 8525 22 376299 3 69312 0 275
|
47
2024/src/day11.clj
Normal file
47
2024/src/day11.clj
Normal 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)
|
Loading…
x
Reference in New Issue
Block a user