Created
August 11, 2016 18:21
-
-
Save anonymous/9828c4f785abe22a72b4f9d99d86f003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
xf.times {puts "UP"} | |
end | |
if xf < 0 | |
xf.times {puts "DOWN"} | |
end | |
if yf > 0 | |
yf.times {puts "LEFT"} | |
end | |
if yf < 0 | |
yf.times {puts "RIGHT"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment