Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def robotPath(instructions, bound)
- x = 0
- start = Array.new
- start = [0,0]
- while (x < instructions.length)
- if instructions[x] == "L" and (start[0] - 1).abs <= bound.abs then
- start[0] = start[0] - 1
- end
- if instructions[x] == "R" and (start[0] + 1).abs <= bound.abs then
- start[0] = start[0] + 1
- end
- if instructions[x] == "U" and (start[1] + 1).abs <= bound.abs then
- start[1] = start[1] + 1
- end
- if instructions[x] == "D" and (start[1] - 1).abs <= bound.abs then
- start[1] = start[1] - 1
- end
- x = x + 1
- end
- return start
- end
Advertisement
Add Comment
Please, Sign In to add comment