From d011cdb55f13c55ffc6bb4b854ef30c2561f2a7c Mon Sep 17 00:00:00 2001 From: Nat Lasseter Date: Wed, 13 Dec 2017 19:07:21 +0000 Subject: Day 12 --- day12/part1 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 day12/part1 (limited to 'day12/part1') 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 -- cgit v1.2.3