public
Last active — forked from kejadlen/maze.rb

  • Download Gist
maze.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
class Maze
def initialize(s)
@m = s.dup
@d = r(@m.index('A'),@m.index("\n")+1)
end
 
def r(a,w)
n = [[1,a]]
until n.empty? do
d,i = n.shift
[i-w,i+w,i-1,i+1].each do |j|
case @m[j]
when 32
@m[j] = 'x'
n << [d+1,j]
when 66
return d
end
end
n.sort!
end
nil
end
 
def solvable?; !!@d; end
def steps; @d || 0; end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.