finish day 11

This commit is contained in:
Adam Jeniski 2025-12-19 13:35:51 -05:00
parent d04209497b
commit f88a28cad2
2 changed files with 15 additions and 36 deletions

1
2025/.gitignore vendored
View File

@ -1,3 +1,4 @@
input/
.lein-repl-history
.idea/
*.iml

View File

@ -1,46 +1,24 @@
(ns day11
(:require input-manager
[clojure.string :as str]))
(:require [input-manager]))
(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"))
(def input (->> (input-manager/get-input 2025 11)
(map (comp (fn [[node & edges]]
[node (into #{} edges)])
(partial re-seq #"[a-z]{3}")))
(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
(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"))))
;; part 2
(+ (* (count-paths "svr" "dac") (count-paths "dac" "fft") (count-paths "fft" "out"))
(* (count-paths "svr" "fft") (count-paths "fft" "dac") (count-paths "dac" "out")))