finish day 11
This commit is contained in:
parent
d04209497b
commit
f88a28cad2
1
2025/.gitignore
vendored
1
2025/.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
input/
|
input/
|
||||||
.lein-repl-history
|
.lein-repl-history
|
||||||
|
.idea/
|
||||||
*.iml
|
*.iml
|
||||||
@ -1,46 +1,24 @@
|
|||||||
(ns day11
|
(ns day11
|
||||||
(:require input-manager
|
(:require [input-manager]))
|
||||||
[clojure.string :as str]))
|
|
||||||
|
|
||||||
(def input (->> (if true
|
(def input (->> (input-manager/get-input 2025 11)
|
||||||
(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]]
|
(map (comp (fn [[node & edges]]
|
||||||
[node (into #{} edges)])
|
[node (into #{} edges)])
|
||||||
(partial re-seq #"[a-z]{3}")))
|
(partial re-seq #"[a-z]{3}")))
|
||||||
(into {})))
|
(into {})))
|
||||||
|
|
||||||
|
(def count-paths
|
||||||
|
(memoize
|
||||||
|
(fn [start target]
|
||||||
|
(let [edges (input start)]
|
||||||
|
(if (contains? edges target)
|
||||||
|
1
|
||||||
|
(apply + (map #(count-paths % target) edges)))))))
|
||||||
|
|
||||||
|
|
||||||
;; part 1
|
;; 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")
|
(count-paths "you" "out")
|
||||||
|
|
||||||
(comment
|
;; part 2
|
||||||
(defn count-paths-2 [start target visisted]
|
(+ (* (count-paths "svr" "dac") (count-paths "dac" "fft") (count-paths "fft" "out"))
|
||||||
(let [edges (input start)
|
(* (count-paths "svr" "fft") (count-paths "fft" "dac") (count-paths "dac" "out")))
|
||||||
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