This commit is contained in:
Adam Jeniski 2024-12-10 11:08:38 -05:00
parent 950ae06a43
commit f9d146d1d9
2 changed files with 12 additions and 15 deletions

View File

@ -54,3 +54,11 @@
"mapv mapv mapv f coll"
[f coll]
(mapv (partial mapv (partial mapv f)) coll))
(defn partition-by-counts [counts coll]
(->> counts
(reduce (fn [[acc coll] c]
(let [[a b] (split-at c coll)]
[(conj acc a) b]))
[[] coll])
first))

View File

@ -3,18 +3,7 @@
[core :as c]
[input-manager :refer [get-input]]))
(defn partition-by-counts [counts coll]
(loop [[c & cs] counts
acc []
coll coll]
(cond
(nil? c) acc
:else (let [[a b] (split-at c coll)]
(recur cs (conj acc a) b)))))
(def input (->>
; (first (get-input 9))
"2333133121414131402"
(def input (->> (first (get-input 9))
(map str)
(map parse-long)))
@ -24,7 +13,7 @@
;; part 1
(let [forward (map-indexed #(repeat %2 %1) smol-nums)]
(->> forward reverse flatten
(partition-by-counts smol-spaces)
(c/partition-by-counts smol-spaces)
(interleave forward)
flatten
(take (reduce + smol-nums))