[2025][ruby][8.x]
change tmszxtrnununnyoluyqvmytkwomqrztt
commit 0a083df8b9c04e6fd09556717114c029e17bb650
author Alpha Chen <alpha@kejadlen.dev>
date
parent uvmxlpkr
diff --git a/2025/ruby/day_08.rb b/2025/ruby/day_08.rb
new file mode 100644
index 0000000..516ee0b
--- /dev/null
+++ b/2025/ruby/day_08.rb
@@ -0,0 +1,34 @@
+boxes = DATA.read.lines.map { it.split(?,).map(&:to_i) }
+
+circuits = boxes.to_h { [it, Set[it]] }
+
+distances = boxes.combination(2).sort_by {|a, b|
+  a.zip(b).sum { (_1 - _2) ** 2 } ** 0.5
+}
+
+# N = 10
+# N.times do
+loop do
+  a, b = distances.shift
+
+  c_a = circuits[a]
+  c_b = circuits[b]
+
+  connected = c_a | c_b
+
+  if connected.size == boxes.size
+    pp a[0] * b[0]
+    exit
+  end
+
+  connected.each do |box|
+    circuits[box] = connected
+  end
+end
+
+pp circuits.values.uniq
+  .map(&:size).sort[-3..]
+  .inject(:*)
+puts
+
+__END__