[2016][ruby][11.0] read state from input

profile
Alpha Chen 8 years ago
parent a78bb9d70a
commit eeb4f8366c

@ -0,0 +1,31 @@
class State
attr_reader :floors, :elevator
def initialize(input)
@floors = input.lines.reverse.map.with_index {|line, index|
_, e, *items = line.split(/\s+/)
@elevator = index if e == ?E
items.reject {|item| item == ?. }
}
end
end
require 'minitest/autorun'
class TestDay11 < Minitest::Test
def test_initialize
input = <<-INPUT
F4 . . . . .
F3 . . . LG .
F2 . HG . . .
F1 E . HM . LM
INPUT
state = State.new(input)
assert_equal 4, state.floors.size
assert_equal 0, state.elevator
floor = state.floors[0]
assert_equal 2, floor.size
end
end
Loading…
Cancel
Save