[2016][ruby][11.0] read state from input
change yvyzrtvmwsplvxnywprlzzkmywoyrrwt
commit b10e71f34217916cd5341d36b196b1b6f3659ccb
author Alpha Chen <alpha.chen@gmail.com>
date
parent nywzyqzl
diff --git a/2016/ruby/day_11.rb b/2016/ruby/day_11.rb
new file mode 100644
index 0000000..7fe53fd
--- /dev/null
+++ b/2016/ruby/day_11.rb
@@ -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