part 1 day 9

This commit is contained in:
Adam Jeniski 2024-12-10 10:25:15 -05:00
parent 8ac20241c9
commit 950ae06a43
2 changed files with 33 additions and 0 deletions

1
2024/input/9.txt Normal file

File diff suppressed because one or more lines are too long

32
2024/src/day09.clj Normal file
View File

@ -0,0 +1,32 @@
(ns day09
(:require
[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"
(map str)
(map parse-long)))
(def smol-nums (->> input (take-nth 2) (into [])))
(def smol-spaces (->> input rest (take-nth 2) (into [])))
;; part 1
(let [forward (map-indexed #(repeat %2 %1) smol-nums)]
(->> forward reverse flatten
(partition-by-counts smol-spaces)
(interleave forward)
flatten
(take (reduce + smol-nums))
(map-indexed *)
(reduce +)))