[2016][ruby][11.0] check for radiated microchips

profile
Alpha Chen 8 years ago
parent 0ff8f7b122
commit 241bb17304

@ -24,6 +24,10 @@ State = Struct.new(:floors, :elevator) do
} }
end end
def irradiated?
floors.any?(&:irradiated?)
end
private private
def current_floor def current_floor
@ -56,6 +60,10 @@ class Floor < SimpleDelegator
def generators def generators
source.select {|item| item.end_with?(?G) }.map {|item| item.chomp(?G) } source.select {|item| item.end_with?(?G) }.map {|item| item.chomp(?G) }
end end
def irradiated?
!(generators.empty? || (microchips - generators).empty?)
end
end end
require 'minitest/autorun' require 'minitest/autorun'
@ -101,4 +109,14 @@ F1 E . HM . LM
assert_equal %W[ HM ], candidate.floors[0] assert_equal %W[ HM ], candidate.floors[0]
assert_equal %W[ HG LM ], candidate.floors[1] assert_equal %W[ HG LM ], candidate.floors[1]
end 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 end

Loading…
Cancel
Save