Day 7 p1
This commit is contained in:
parent
36f64d39fe
commit
ac2ca562e9
58
2025.clj
58
2025.clj
@ -348,3 +348,61 @@ L82")
|
|||||||
(day6-p2 day6-input-test) ;; => 3263827
|
(day6-p2 day6-input-test) ;; => 3263827
|
||||||
(day6-p2 (get-input 6)) ;; => 11136895955912
|
(day6-p2 (get-input 6)) ;; => 11136895955912
|
||||||
:-)
|
:-)
|
||||||
|
|
||||||
|
;; _____ ______
|
||||||
|
;; | __ \ |____ |
|
||||||
|
;; | | | | __ _ _ _ / /
|
||||||
|
;; | | | |/ _` | | | | / /
|
||||||
|
;; | |__| | (_| | |_| | / /
|
||||||
|
;; |_____/ \__,_|\__, | /_/
|
||||||
|
;; __/ |
|
||||||
|
;; |___/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
(def day7-input-test
|
||||||
|
".......S.......
|
||||||
|
...............
|
||||||
|
.......^.......
|
||||||
|
...............
|
||||||
|
......^.^......
|
||||||
|
...............
|
||||||
|
.....^.^.^.....
|
||||||
|
...............
|
||||||
|
....^.^...^....
|
||||||
|
...............
|
||||||
|
...^.^...^.^...
|
||||||
|
...............
|
||||||
|
..^...^.....^..
|
||||||
|
...............
|
||||||
|
.^.^.^.^.^...^.
|
||||||
|
...............")
|
||||||
|
|
||||||
|
(defn day7-p1 [input]
|
||||||
|
(let [lanes (->> (str/split-lines input)
|
||||||
|
(mapv vec)
|
||||||
|
(apply mapv vector))
|
||||||
|
length (count (first lanes))]
|
||||||
|
(loop [active-lanes (set (keep-indexed #(when (= (first %2) \S) %1) lanes))
|
||||||
|
idx 2 ;; The splitters start on row 3
|
||||||
|
count 0]
|
||||||
|
(if (= idx length)
|
||||||
|
count
|
||||||
|
(let [[new-lanes added-count]
|
||||||
|
(reduce (fn [[ls c] lane]
|
||||||
|
(if (not= \^ (get-in lanes [lane idx]))
|
||||||
|
[ls c]
|
||||||
|
[(conj (disj ls lane) (dec lane) (inc lane)) (inc c)]))
|
||||||
|
[active-lanes 0]
|
||||||
|
active-lanes)]
|
||||||
|
(recur new-lanes (inc idx) (+ count added-count)))))))
|
||||||
|
|
||||||
|
(defn day7-p2 [input]
|
||||||
|
())
|
||||||
|
|
||||||
|
(comment
|
||||||
|
(day7-p1 day7-input-test)
|
||||||
|
(day7-p1 (get-input 7))
|
||||||
|
(day7-p2 day7-input-test)
|
||||||
|
(day7-p2 (get-input 7))
|
||||||
|
:-)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user