Created
August 11, 2016 18:32
-
-
Save anonymous/9548203b0bb3c2580a987c04615d5486 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 && 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