mirror of
https://github.com/Ajetski/advent-of-code.git
synced 2025-09-30 09:23:17 -09:00
do part 2
This commit is contained in:
parent
1761b0fd42
commit
a18e813f94
@ -1,8 +1,8 @@
|
|||||||
(ns day23
|
(ns day23
|
||||||
(:require
|
(:require
|
||||||
[clojure.math :as math]
|
|
||||||
[clojure.math.combinatorics :as combo]
|
[clojure.math.combinatorics :as combo]
|
||||||
[clojure.string :as s]
|
[clojure.set :as set]
|
||||||
|
[clojure.string :as str]
|
||||||
[core :as c :refer :all]
|
[core :as c :refer :all]
|
||||||
[input-manager :as i]))
|
[input-manager :as i]))
|
||||||
|
|
||||||
@ -17,7 +17,7 @@
|
|||||||
flatten
|
flatten
|
||||||
set))
|
set))
|
||||||
|
|
||||||
;; part 1
|
;; part 1, find interconncceted combos of 3 with nodes with at least one like #"t.*"
|
||||||
(def part-1-ans
|
(def part-1-ans
|
||||||
(future
|
(future
|
||||||
(->> (combo/combinations edges 2)
|
(->> (combo/combinations edges 2)
|
||||||
@ -33,12 +33,36 @@
|
|||||||
(map set)
|
(map set)
|
||||||
set
|
set
|
||||||
count)))
|
count)))
|
||||||
(future
|
|
||||||
(println "processing part 1...")
|
|
||||||
(println "part 1 answer:" @part-1-ans))
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
|
|
||||||
|
(future
|
||||||
|
(println "processing part 1...")
|
||||||
|
(println "part 1 answer:" @part-1-ans))
|
||||||
|
|
||||||
(realized? part-1-ans)
|
(realized? part-1-ans)
|
||||||
(deref part-1-ans 0 "still processing")
|
(deref part-1-ans 0 "still processing")
|
||||||
@part-1-ans)
|
@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)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user