オフラインリアルタイムどう書くE13 の回答


参加して解きました。
a = [ 0, 0, ]
b = [ 2, 0, ]
f = [ 1, 1, ]
として座標を設定してf03と同じロジックを使っています。

```ruby:f13.rb
def solve( input )
  board = input.split('').map { |c|
    offset = c.ord - 'a'.ord
    case offset
    when 0...5
      [ offset * 2, 0, ]
    when 5...9
      [ (offset - 5) * 2 + 1, 1, ]
    when 9...14
      [ (offset - 9) * 2, 2, ]
    when 14...18
      [ (offset - 14) * 2 + 1, 3, ]
    when 18...23
      [ (offset - 18) * 2, 4, ]
    end
  }.sort

  start = board.transpose.map { |a|
    a.min
  }

  board = board.map { |point|
    point.zip(start).map { |l ,r|
      l - r
    }
  }

  {
    [ [ 0, 0, ], [ 1, 1, ], [ 2, 2, ], [ 3, 1, ], ] => 'B',
    [ [ 0, 1, ], [ 2, 1, ], [ 3, 0, ], [ 4, 1, ], ] => 'B',
    [ [ 0, 1, ], [ 1, 0, ], [ 2, 1, ], [ 3, 2, ], ] => 'B',
    [ [ 0, 2, ], [ 1, 1, ], [ 2, 0, ], [ 2, 2, ], ] => 'B',
    [ [ 0, 0, ], [ 0, 2, ], [ 1, 1, ], [ 2, 0, ], ] => 'B',
    [ [ 0, 0, ], [ 1, 1, ], [ 2, 0, ], [ 4, 0, ], ] => 'B',
    [ [ 0, 0, ], [ 0, 2, ], [ 1, 1, ], [ 2, 2, ], ] => 'D',
    [ [ 0, 1, ], [ 1, 0, ], [ 2, 1, ], [ 4, 1, ], ] => 'D',
    [ [ 0, 0, ], [ 2, 0, ], [ 3, 1, ], [ 4, 0, ], ] => 'D',
    [ [ 0, 1, ], [ 1, 2, ], [ 2, 1, ], [ 3, 0, ], ] => 'D',
    [ [ 0, 0, ], [ 1, 1, ], [ 2, 0, ], [ 2, 2, ], ] => 'D',
    [ [ 0, 2, ], [ 1, 1, ], [ 2, 0, ], [ 3, 1, ], ] => 'D',
    [ [ 0, 0, ], [ 2, 0, ], [ 4, 0, ], [ 6, 0, ], ] => 'I',
    [ [ 0, 0, ], [ 1, 1, ], [ 2, 2, ], [ 3, 3, ], ] => 'I',
    [ [ 0, 3, ], [ 1, 2, ], [ 2, 1, ], [ 3, 0, ], ] => 'I',
  }[board] || '-'
end


def test( input, answer )
  result = solve(input)
  if result != answer
    puts 'NG, input = %s, answer = %s, result = %s' % [ input, answer, result, ]
    exit 1
  else
    puts 'OK'
  end
end

test( "glmq", "B" )
test( "fhoq", "-" )
test( "lmpr", "-" )
test( "glmp", "-" )
test( "dhkl", "-" )
test( "glpq", "D" )
test( "hlmq", "-" )
test( "eimq", "I" )
test( "cglp", "-" )
test( "chlq", "-" )
test( "glqr", "-" )
test( "cdef", "-" )
test( "hijk", "-" )
test( "kpqu", "B" )
test( "hklm", "B" )
test( "mqrw", "B" )
test( "nrvw", "B" )
test( "abfj", "B" )
test( "abcf", "B" )
test( "mrvw", "D" )
test( "ptuv", "D" )
test( "lmnr", "D" )
test( "hklp", "D" )
test( "himr", "D" )
test( "dhil", "D" )
test( "hlpt", "I" )
test( "stuv", "I" )
test( "bglq", "I" )
test( "glmn", "-" )
test( "fghm", "-" )
test( "cdgk", "-" )
test( "lpst", "-" )
test( "imrw", "-" )
test( "dinr", "-" )
test( "cdin", "-" )
test( "eghi", "-" )
test( "cdeg", "-" )
test( "bgko", "-" )
test( "eimr", "-" )
test( "jotu", "-" )
test( "kotu", "-" )
test( "lqtu", "-" )
test( "cdim", "-" )
test( "klot", "-" )
test( "kloq", "-" )
test( "kmpq", "-" )
test( "qrvw", "-" )
test( "mnqr", "-" )
test( "kopt", "-" )
test( "mnpq", "-" )
test( "bfko", "-" )
test( "chin", "-" )
test( "hmnq", "-" )
test( "nqrw", "-" )
test( "bchi", "-" )
test( "inrw", "-" )
test( "cfgj", "-" )
test( "jnpv", "-" )
test( "flmp", "-" )
test( "adpw", "-" )
test( "eilr", "-" )
test( "bejv", "-" )
test( "enot", "-" )
test( "fghq", "-" )
test( "cjms", "-" )
test( "elov", "-" )
test( "chlm", "D" )
test( "acop", "-" )
test( "finr", "-" )
test( "qstu", "-" )
test( "abdq", "-" )
```

さすがハッシュのパターンが増えるので、座標を作るときに回転を考えようと実装していましたが時間切れになりました。