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" "mapv mapv mapv f coll"
[f coll] [f coll]
(mapv (partial mapv (partial mapv 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,20 +3,9 @@
[core :as c] [core :as c]
[input-manager :refer [get-input]])) [input-manager :refer [get-input]]))
(defn partition-by-counts [counts coll] (def input (->> (first (get-input 9))
(loop [[c & cs] counts (map str)
acc [] (map parse-long)))
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"
(map str)
(map parse-long)))
(def smol-nums (->> input (take-nth 2) (into []))) (def smol-nums (->> input (take-nth 2) (into [])))
(def smol-spaces (->> input rest (take-nth 2) (into []))) (def smol-spaces (->> input rest (take-nth 2) (into [])))
@ -24,7 +13,7 @@
;; part 1 ;; part 1
(let [forward (map-indexed #(repeat %2 %1) smol-nums)] (let [forward (map-indexed #(repeat %2 %1) smol-nums)]
(->> forward reverse flatten (->> forward reverse flatten
(partition-by-counts smol-spaces) (c/partition-by-counts smol-spaces)
(interleave forward) (interleave forward)
flatten flatten
(take (reduce + smol-nums)) (take (reduce + smol-nums))