diff --git a/2024/src/day23.clj b/2024/src/day23.clj index abee192..60fbcab 100644 --- a/2024/src/day23.clj +++ b/2024/src/day23.clj @@ -1,8 +1,8 @@ (ns day23 (:require - [clojure.math :as math] [clojure.math.combinatorics :as combo] - [clojure.string :as s] + [clojure.set :as set] + [clojure.string :as str] [core :as c :refer :all] [input-manager :as i])) @@ -17,7 +17,7 @@ flatten set)) -;; part 1 +;; part 1, find interconncceted combos of 3 with nodes with at least one like #"t.*" (def part-1-ans (future (->> (combo/combinations edges 2) @@ -33,12 +33,36 @@ (map set) set count))) -(future - (println "processing part 1...") - (println "part 1 answer:" @part-1-ans)) (comment + + (future + (println "processing part 1...") + (println "part 1 answer:" @part-1-ans)) + (realized? part-1-ans) (deref part-1-ans 0 "still processing") @part-1-ans) +(defn make-graph [nodes edges] + (reduce (fn [graph el] + (assoc graph el (->> (filter #(contains? % el) edges) + (map #(disj % el)) + (map first) + (set)))) + {} + nodes)) + +(def graph (make-graph nodes edges)) + +;; part 2, find largest interconnected subgraph +(->> (for [guess (->> graph + (map reverse) + (map (partial apply conj))) + part (combo/combinations (seq guess) 1)] + (reduce set/intersection + (map #(apply sorted-set (conj (graph %) %)) + (apply disj guess part)))) + (filter (compose count #(> % 1))) + (map (partial str/join ",")) + (apply max-key (compose (partial filter #(= \, %)) count)))