mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 07:03:19 -09:00
refactor
This commit is contained in:
parent
950ae06a43
commit
f9d146d1d9
@ -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))
|
||||||
|
@ -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))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user