aboutsummaryrefslogtreecommitdiff
path: root/racket/aoc2023/day-25/day-25.rkt
diff options
context:
space:
mode:
authorH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
committerH.J <thechairman@thechairman.info>2024-10-09 11:36:55 -0400
commit8777ff071f7bb37631baa7b6717ad29961e50911 (patch)
tree6d59c4ed58e454b960339c3d1151f0a879e8d7cb /racket/aoc2023/day-25/day-25.rkt
parent6156a9ef7be4012063a042aafb4e9b0d7eadde8e (diff)
downloadgleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.tar.gz
gleam_aoc-8777ff071f7bb37631baa7b6717ad29961e50911.zip
sorting by language
Diffstat (limited to 'racket/aoc2023/day-25/day-25.rkt')
-rw-r--r--racket/aoc2023/day-25/day-25.rkt43
1 files changed, 43 insertions, 0 deletions
diff --git a/racket/aoc2023/day-25/day-25.rkt b/racket/aoc2023/day-25/day-25.rkt
new file mode 100644
index 0000000..aa32e43
--- /dev/null
+++ b/racket/aoc2023/day-25/day-25.rkt
@@ -0,0 +1,43 @@
+#lang racket
+
+(require advent-of-code
+ threading
+ graph)
+
+(define input
+ (~> (fetch-aoc-input (find-session) 2023 25 #:cache #true)
+ (string-split "\n")
+ (map (curryr string-split ": ") _)))
+
+(define all-wires
+ (for*/list ([wire-diagram (in-list input)] [devices (in-list (string-split (second wire-diagram)))])
+ (list (car wire-diagram) devices)))
+
+;; instead of trying to solve the minimum cut problem, I generated the graph and
+;; rendered it in graphviz:
+
+; (define out (open-output-file "graphviz"))
+; (~> all-wires
+; unweighted-graph/undirected
+; graphviz
+; (display out))
+; (close-output-port out)
+
+;; the bottleneck is very obvious on the graph --
+;; there's two large clusters of nodes, connected by just three edges
+;;
+;; from the graphviz output, the three critical wires are
+;; cpq-hlx
+;; hqp-spk
+;; chr-zlx
+
+(define remove-these-three '(("cpq" "hlx") ("hqp" "spk") ("chr" "zlx")))
+(define cut-wires
+ (for/list ([wire (in-list all-wires)] #:unless (member (sort wire string<?) remove-these-three))
+ wire))
+
+(~> cut-wires
+ unweighted-graph/undirected
+ scc
+ (map length _)
+ (apply * _)) \ No newline at end of file