aboutsummaryrefslogtreecommitdiff
path: root/day12/part1
diff options
context:
space:
mode:
Diffstat (limited to 'day12/part1')
-rwxr-xr-xday12/part131
1 files changed, 31 insertions, 0 deletions
diff --git a/day12/part1 b/day12/part1
new file mode 100755
index 0000000..ac3f087
--- /dev/null
+++ b/day12/part1
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+input = $stdin.readlines.map(&:chomp)
+
+pipes = []
+
+input.each do |line|
+ me, them = line.split(' <-> ')
+ me = me.to_i
+ them = them.split(', ').map(&:to_i)
+
+ pipes[me] = [] if pipes[me].nil?
+ them.each do |p|
+ pipes[me] << p
+ end
+end
+
+group = [0]
+visited = []
+queue = [0]
+
+until queue.empty? do
+ here = queue.shift
+ visited << here
+ pipes[here].each do |p|
+ group << p
+ queue << p unless visited.include?(p)
+ end
+end
+
+p group.uniq.length