[2016][ruby][11.0] check for radiated microchips
diff --git a/2016/ruby/day_11.rb b/2016/ruby/day_11.rb
index bddda18..d0a187e 100644
--- a/2016/ruby/day_11.rb
+++ b/2016/ruby/day_11.rb
@@ -24,6 +24,10 @@ State = Struct.new(:floors, :elevator) do
}
end
+ def irradiated?
+ floors.any?(&:irradiated?)
+ end
+
private
def current_floor
@@ -56,6 +60,10 @@ class Floor < SimpleDelegator
def generators
source.select {|item| item.end_with?(?G) }.map {|item| item.chomp(?G) }
end
+
+ def irradiated?
+ !(generators.empty? || (microchips - generators).empty?)
+ end
end
require 'minitest/autorun'
@@ -101,4 +109,14 @@ F1 E . HM . LM
assert_equal %W[ HM ], candidate.floors[0]
assert_equal %W[ HG LM ], candidate.floors[1]
end
+
+ def test_irradiated
+ refute Floor.new(%w[]).irradiated?
+ refute Floor.new(%w[ BM ]).irradiated?
+ refute Floor.new(%w[ BG ]).irradiated?
+ refute Floor.new(%w[ BM BG ]).irradiated?
+ refute Floor.new(%w[ BM BG LG ]).irradiated?
+
+ assert Floor.new(%w[ BM LG ]).irradiated?
+ end
end