|
|
@ -21,10 +21,13 @@ def patrol(lab)
|
|
|
|
loop do
|
|
|
|
loop do
|
|
|
|
pos, dir = path.last
|
|
|
|
pos, dir = path.last
|
|
|
|
peek = pos.zip(dir).map {|i,di| i + di }
|
|
|
|
peek = pos.zip(dir).map {|i,di| i + di }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return path unless lab.has_key?(peek)
|
|
|
|
|
|
|
|
|
|
|
|
raise Loop if seen.include?([peek, dir])
|
|
|
|
raise Loop if seen.include?([peek, dir])
|
|
|
|
seen << [peek, dir]
|
|
|
|
seen << [peek, dir]
|
|
|
|
|
|
|
|
|
|
|
|
case lab.fetch(peek, nil)
|
|
|
|
case lab.fetch(peek)
|
|
|
|
when ?., ?^
|
|
|
|
when ?., ?^
|
|
|
|
path << [peek, dir]
|
|
|
|
path << [peek, dir]
|
|
|
|
when ?#
|
|
|
|
when ?#
|
|
|
|