「オフラインリアルタイムどう書く第10回(ハニカム歩き)」の問題を解いてみた(妥協版)


[横浜へなちょこプログラミング勉強会](https://yhpg.doorkeeper.jp/)にて過去に出題された[ハニカム歩き](http://nabetani.sakura.ne.jp/hena/ord10haniwa/)を解いてみた。
回答にかかった時間は40分。

結局回答とした実装はすぐに浮かんだのだが、このような力技ではやりたくないと思い他の実装を模索していた。
結局うまく実装できなかったので時間内で解くために力技に頼らざるを得なくなってしまった。
それっぽい戦略は立ててあるので、後ほど再チャレンジしたい。

```ruby
class HoneyComb
  MAP = {
    "A" => "BCDEFG", "B" => "HICAGS", "C" => "IJKDAB", "D" => "CKLMEA", "E" => "ADMNOF", "F" => "GAEOPQ",
    "G" => "SBAFQR", "H" => "TUIBSk", "I" => "UVJCBH", "J" => "VWXKCI", "K" => "JXYLDC", "L" => "KYZaMD",
    "M" => "DLabNE", "N" => "EMbcdO", "O" => "FENdeP", "P" => "QFOefg", "Q" => "RGFPgh", "R" => "jSGQhi",
    "S" => "kHBGRj", "T" => "!!UHk!", "U" => "!!VIHT", "V" => "!!WJIU", "W" => "!!!XJV", "X" => "W!!YKJ",
    "Y" => "X!!ZLK", "Z" => "Y!!!aL", "a" => "LZ!!bM", "b" => "Ma!!cN", "c" => "Nb!!!d", "d" => "ONc!!e",
    "e" => "POd!!f", "f" => "gPe!!!", "g" => "hQPf!!", "h" => "iRQg!!", "i" => "!jRh!!", "j" => "!kSRi!",
    "k" => "!THSj!"
  }

  def route input
    input.each_char.each_with_object(["A"]){|n, r|
      r << MAP[r[r.rindex{|point| point != "!"}]][n.to_i]
    }.join
  end
end

test = <<_TEST
/*0*/ test( "135004", "ACDABHS" );
/*1*/ test( "1", "AC" );
/*2*/ test( "33333120", "AENc!!b!M" );
/*3*/ test( "0", "AB" );
/*4*/ test( "2", "AD" );
/*5*/ test( "3", "AE" );
/*6*/ test( "4", "AF" );
/*7*/ test( "5", "AG" );
/*8*/ test( "4532120", "AFQPOEMD" );
/*9*/ test( "051455", "ABSHSj!" );
/*10*/ test( "23334551", "ADMb!cdeO" );
/*11*/ test( "22033251", "ADLKLa!ML" );
/*12*/ test( "50511302122", "AGSjkTHTU!VW" );
/*13*/ test( "000051", "ABHT!!!" );
/*14*/ test( "1310105", "ACDKJW!V" );
/*15*/ test( "50002103140", "AGSk!HU!IVIU" );
/*16*/ test( "3112045", "AEDKYXKC" );
/*17*/ test( "02021245535", "ABCIJW!JIHBS" );
/*18*/ test( "014204", "ABIBCIB" );
/*19*/ test( "255230", "ADAGAEA" );
/*20*/ test( "443501", "AFPefgQ" );
/*21*/ test( "022321", "ABCKLZ!" );
/*22*/ test( "554452", "AGRh!!Q" );
/*23*/ test( "051024", "ABSHTUH" );
/*24*/ test( "524002", "AGAFGSB" );
/*25*/ test( "54002441132", "AGQRjSRhRSGA" );
/*26*/ test( "11010554312", "ACJV!!UTkSHI" );
/*27*/ test( "23405300554", "ADMNEFOFGRi!" );
/*28*/ test( "555353201", "AGRih!gPQG" );
/*29*/ test( "22424105", "ADLMabaLD" );
/*30*/ test( "11340202125", "ACJKDCKJX!!J" );
/*31*/ test( "4524451", "AFQFPf!P" );
/*32*/ test( "44434234050", "AFPf!!e!!Pgh" );
/*33*/ test( "00554040132", "ABHk!j!i!jRG" );
/*34*/ test( "3440403", "AEOePfgf" );
/*35*/ test( "111130", "ACJW!XW" );
/*36*/ test( "21133343125", "ADKXYZ!a!Z!L" );
/*37*/ test( "353511", "AEFOPFA" );
/*38*/ test( "22204115220", "ADLZYLY!KY!X" );
/*39*/ test( "03013541", "ABABICBGB" );
/*40*/ test( "101344", "ACIVJCA" );
/*41*/ test( "2432541", "ADENbNdN" );
/*42*/ test( "45332242015", "AFQPedc!!NME" );
/*43*/ test( "215453", "ADKCAGF" );
/*44*/ test( "45540523454", "AFQh!i!RQg!!" );
/*45*/ test( "42434302545", "AFEOd!!ONOef" );
_TEST

require 'minitest/autorun'

describe 'HoneyComb' do
  test.split("\n").each do |line|
    t, n, input, expect = line.match(/^\/\*(\d+)\*\/\s*test\(\s*"([^"]+)",\s*"([^"]+)"\s*\);$/).to_a
    hc = HoneyComb.new
    it input do
      assert_equal expect, hc.route(input)
    end
  end
end
```