aboutsummaryrefslogtreecommitdiff
path: root/day12/part1
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-13 19:07:21 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-13 19:07:21 +0000
commitd011cdb55f13c55ffc6bb4b854ef30c2561f2a7c (patch)
treeb76eee0e4b0c1106131d7c698d755fce502735c3 /day12/part1
parent91fbd98401dcde40c483cad42b746115d133bbd1 (diff)
Day 12
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