mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 12:12:44 -10:00
day 19 do part 2
This commit is contained in:
parent
bf47ff7c34
commit
57c87a2c13
@ -79,7 +79,36 @@ bbrgwb")
|
|||||||
next-subsets
|
next-subsets
|
||||||
(inc n))))))))
|
(inc n))))))))
|
||||||
|
|
||||||
|
;; part 1 solution
|
||||||
(->> puzzles
|
(->> puzzles
|
||||||
(map is-valid)
|
(map is-valid)
|
||||||
(filter identity)
|
(filter identity)
|
||||||
count)
|
count)
|
||||||
|
|
||||||
|
(defn valid-combination-count
|
||||||
|
([puzzle]
|
||||||
|
(valid-combination-count puzzle
|
||||||
|
0
|
||||||
|
1
|
||||||
|
(mapv (constantly 0) puzzle)))
|
||||||
|
;; dp is vec of ints which contains the count of combinations for substring from puzzle[0] and ending at puzzle[n]
|
||||||
|
([puzzle pos weight dp]
|
||||||
|
(if (>= pos (count puzzle))
|
||||||
|
(last dp)
|
||||||
|
(let [dp' (->> (map (partial + pos) word-sizes)
|
||||||
|
(filter (partial >= (count puzzle)))
|
||||||
|
(map (partial subs puzzle pos))
|
||||||
|
(filter words)
|
||||||
|
(map (comp dec count))
|
||||||
|
(map (partial + pos))
|
||||||
|
(reduce (fn [acc idx] (update acc idx (partial + weight)))
|
||||||
|
dp))]
|
||||||
|
(recur puzzle
|
||||||
|
(inc pos)
|
||||||
|
(or (get dp' pos) 0)
|
||||||
|
dp')))))
|
||||||
|
|
||||||
|
;; part 2 solution
|
||||||
|
(->> puzzles
|
||||||
|
(map valid-combination-count)
|
||||||
|
(apply +))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user