Skip to content

Instantly share code, notes, and snippets.

Created August 11, 2016 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9548203b0bb3c2580a987c04615d5486 to your computer and use it in GitHub Desktop.
Save anonymous/9548203b0bb3c2580a987c04615d5486 to your computer and use it in GitHub Desktop.
#!/bin/ruby
m = gets.to_i
grid = Array.new(m)
(0...m).each do |i|
grid[i] = gets.strip
end
new = []
grid.each do |x|
new << x.chars
end
i = 0
while i < new.length
if new[i].index("m") != nil
x = i
y = new[x].index("m")
end
i += 1
end
#xy - m
i = 0
while i < new.length
if new[i].index("p") != nil
x1 = i
y1 = new[x1].index("p")
end
i += 1
end
#x1y1 - p
xf = x - x1
yf = y - y1
if xf > 0 && yf > 0
xf.times {puts "UP"}
yf.times {puts "LEFT"}
end
if xf < 0 && yf < 0
xf.abs.times {puts "DOWN"}
yf.abs.times {puts "RIGHT"}
end
if yf > 0 && xf < 0
yf.abs.times {puts "LEFT"}
xf.abs.times {puts "DOWN"}
end
if yf < 0 && xf > 0
yf.abs.times {puts "RIGHT"}
xf.abs.times {puts "UP"}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment