From f88a28cad242adb315b61f23cbc4f5a6ccbe6fc9 Mon Sep 17 00:00:00 2001 From: ajet Date: Fri, 19 Dec 2025 13:35:51 -0500 Subject: [PATCH] finish day 11 --- 2025/.gitignore | 1 + 2025/src/day11.clj | 50 +++++++++++++--------------------------------- 2 files changed, 15 insertions(+), 36 deletions(-) diff --git a/2025/.gitignore b/2025/.gitignore index faa2c58..57a76f9 100644 --- a/2025/.gitignore +++ b/2025/.gitignore @@ -1,3 +1,4 @@ input/ .lein-repl-history +.idea/ *.iml \ No newline at end of file diff --git a/2025/src/day11.clj b/2025/src/day11.clj index b9a1e27..b5f6c12 100644 --- a/2025/src/day11.clj +++ b/2025/src/day11.clj @@ -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")))