Help us understand the problem. What is going on with this article?

オフラインリアルタイムどう書く第5回の参考問題をRubyで解く

More than 5 years have passed since last update.

問題はこちら
http://qiita.com/items/0ddde0164a745cd09c34

1次元配列で番兵を使った。あまりRubyらしくないかも。

MOVE = {
  0 => { 4=> 4,-4=>-4, 1=> 1,-1=>-1},
  1 => { 4=> 1,-4=>-1, 1=> 4,-1=>-4},
  2 => { 4=>-1,-4=> 1, 1=>-4,-1=> 4},
}
BOARD = '----ABC-DEF-GHI----'.split('')

def solve(q)
  pat = ('----%c%c%c-%c%c%c-%c%c%c----'%q.split('')).split('').map{|e| e=='-' ? -1:e.to_i}
  pos, mv = [5, 4]
  a = ''
  until(pat[pos]<0)
    a += BOARD[pos]
    mv = MOVE[pat[pos]][mv]
    pos += mv
  end
  a
end

DATA.readlines.each do |line|
  no,q,a = line.chop.split(/\s+/)
  ans = solve(q)
  print ans
  puts ans == a ? ' o' : ' x'
end
__END__
#0  101221102   BEDGHIFEH
#1  000000000   BEH
nidouchi
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away