「人材獲得作戦・4 試験問題ほか: 人生を書き換える者すらいた。」で出題されている問題を解いてみた。 maze = [] dist = [] sx, sy, gx, gy = nil,nil,nil,nil readlines.each_with_index do |l, y| next if l.chomp.empty? maze.push([]) dist.push([]) l.chomp.split(//).each_with_index do |c, x| maze.last.push(c) dist.last.push(-1) sx, sy = x, y if c == 'S' gx, gy = x, y if c == 'G' end end Direction = [[-1,0],[1,0],[0,-1],[0,1]] que = [] que.push([0, sx, sy