mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-11-27 14:42:43 -10:00
Compare commits
No commits in common. "bf47ff7c34da5aaa819c4a1dc8e0c71d0e868294" and "125891900bce271a22cfd564b2277358c9b0bc76" have entirely different histories.
bf47ff7c34
...
125891900b
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,4 +1,4 @@
|
|||||||
target/
|
*/target/
|
||||||
*/.vscode/
|
*/.vscode/
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
:url "http://github.com/ajetski/advent-of-code"
|
:url "http://github.com/ajetski/advent-of-code"
|
||||||
:min-lein-version "2.0.0"
|
:min-lein-version "2.0.0"
|
||||||
:jvm-opts ["-Xmx16g"]
|
:jvm-opts ["-Xmx16g"]
|
||||||
:plugins [[cider/cider-nrepl "0.57.0"]]
|
|
||||||
:dependencies [[org.clojure/clojure "1.12.0"]
|
:dependencies [[org.clojure/clojure "1.12.0"]
|
||||||
[org.clojure/math.combinatorics "0.3.0"]
|
[org.clojure/math.combinatorics "0.3.0"]
|
||||||
[babashka/fs "0.5.23"]
|
[babashka/fs "0.5.23"]
|
||||||
|
|||||||
@ -1,85 +0,0 @@
|
|||||||
(ns day19
|
|
||||||
(:require
|
|
||||||
[clojure.string :as str] ; [core :as c]
|
|
||||||
input-manager
|
|
||||||
[orchard.pp :as pp]))
|
|
||||||
|
|
||||||
(def sample-input "r, wr, b, g, bwu, rb, gb, br
|
|
||||||
|
|
||||||
brwrr
|
|
||||||
bggr
|
|
||||||
gbbr
|
|
||||||
rrbgbr
|
|
||||||
ubwu
|
|
||||||
bwurrg
|
|
||||||
brgr
|
|
||||||
bbrgwb")
|
|
||||||
|
|
||||||
(let [[w _ & p]
|
|
||||||
#_(str/split-lines sample-input)
|
|
||||||
(input-manager/get-input 2024 19)]
|
|
||||||
(def words (into #{} (str/split w #", ")))
|
|
||||||
(def puzzles p)
|
|
||||||
(def word-sizes (->> words
|
|
||||||
(map count)
|
|
||||||
distinct
|
|
||||||
sort
|
|
||||||
reverse)))
|
|
||||||
|
|
||||||
(defn p [x]
|
|
||||||
(println x)
|
|
||||||
x)
|
|
||||||
|
|
||||||
(defn next-search-index [puzzle searched valid-subsets]
|
|
||||||
(if (every? (complement true?) searched)
|
|
||||||
0
|
|
||||||
(some->> valid-subsets
|
|
||||||
(map-indexed vector)
|
|
||||||
(filter second)
|
|
||||||
(filter (fn [[idx :as el]]
|
|
||||||
(not (searched (inc idx)))))
|
|
||||||
last
|
|
||||||
first
|
|
||||||
inc)))
|
|
||||||
|
|
||||||
(defn find-valid-subsets [puzzle search-idx valid-subsets]
|
|
||||||
(let [max-idx (count puzzle)]
|
|
||||||
(->> word-sizes
|
|
||||||
(map (partial + search-idx)) ; get end pos
|
|
||||||
(filter #(<= % max-idx))
|
|
||||||
(map (partial subs puzzle search-idx)) ;get substrings
|
|
||||||
(filter words)
|
|
||||||
(map (comp (partial + search-idx) dec count))
|
|
||||||
(reduce (fn [acc idx]
|
|
||||||
(assoc acc idx true))
|
|
||||||
valid-subsets))))
|
|
||||||
|
|
||||||
(defn is-valid
|
|
||||||
([puzzle]
|
|
||||||
(is-valid puzzle
|
|
||||||
(mapv (constantly false) puzzle)
|
|
||||||
(mapv (constantly false) puzzle)
|
|
||||||
0))
|
|
||||||
([puzzle searched valid-subsets n]
|
|
||||||
(let [search-idx (next-search-index puzzle searched valid-subsets)]
|
|
||||||
(cond
|
|
||||||
(or (not search-idx)
|
|
||||||
(= search-idx -1))
|
|
||||||
false
|
|
||||||
|
|
||||||
(>= search-idx (count puzzle))
|
|
||||||
true
|
|
||||||
|
|
||||||
:else
|
|
||||||
(let [next-subsets (find-valid-subsets puzzle search-idx valid-subsets)]
|
|
||||||
(if (last next-subsets)
|
|
||||||
true
|
|
||||||
(recur puzzle
|
|
||||||
(assoc searched search-idx true)
|
|
||||||
next-subsets
|
|
||||||
(inc n))))))))
|
|
||||||
|
|
||||||
(->> puzzles
|
|
||||||
(map is-valid)
|
|
||||||
(filter identity)
|
|
||||||
count)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user