mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 13:03:19 -09:00
part 1 day 9
This commit is contained in:
parent
8ac20241c9
commit
950ae06a43
1
2024/input/9.txt
Normal file
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
32
2024/src/day09.clj
Normal 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 +)))
|
Loading…
x
Reference in New Issue
Block a user