do day11 part 1
This commit is contained in:
parent
9ea11f35c9
commit
d04209497b
46
2025/src/day11.clj
Normal file
46
2025/src/day11.clj
Normal file
@ -0,0 +1,46 @@
|
||||
(ns day11
|
||||
(:require input-manager
|
||||
[clojure.string :as str]))
|
||||
|
||||
(def input (->> (if true
|
||||
(input-manager/get-input 2025 11)
|
||||
(str/split-lines "svr: aaa bbb
|
||||
aaa: fft
|
||||
fft: ccc
|
||||
bbb: tty
|
||||
tty: ccc
|
||||
ccc: ddd eee
|
||||
ddd: hub
|
||||
hub: fff
|
||||
eee: dac
|
||||
dac: fff
|
||||
fff: ggg hhh
|
||||
ggg: out
|
||||
hhh: out"))
|
||||
(map (comp (fn [[node & edges]]
|
||||
[node (into #{} edges)])
|
||||
(partial re-seq #"[a-z]{3}")))
|
||||
(into {})))
|
||||
|
||||
;; part 1
|
||||
(defn count-paths [start target]
|
||||
(let [edges (input start)]
|
||||
(if (contains? edges target)
|
||||
1
|
||||
(apply + (map #(count-paths % target) edges)))))
|
||||
(count-paths "you" "out")
|
||||
|
||||
(comment
|
||||
(defn count-paths-2 [start target visisted]
|
||||
(let [edges (input start)
|
||||
visisted' (conj visisted start)]
|
||||
(cond (contains? edges target) 1
|
||||
(contains? visisted start) 0
|
||||
:else
|
||||
(apply + (map #(count-paths-2 % target visisted') edges)))))
|
||||
|
||||
(count-paths-2 "dac" "out" #{})
|
||||
(count-paths-2 "fft" "dac" #{})
|
||||
(+ (* (count-paths "svr" "dac") (count-paths "dac" "fft") (count-paths "fft" "out"))
|
||||
(* (count-paths "svr" "fft") (count-paths "fft" "dac") (count-paths "dac" "out"))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user