From 241bb17304e328d92d4dc4ae526cc81d84b6e898 Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 11 Dec 2016 11:54:34 -0500 Subject: [PATCH] [2016][ruby][11.0] check for radiated microchips --- 2016/ruby/day_11.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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