def robot_move(n, commands):
answer = [1, 1]
for i in range(len(commands)):
if commands[i] == "R" and answer[1] < n:
answer[1] += 1
elif commands[i] == "L" and answer[1] > 1:
answer[1] -= 1
elif commands[i] == "U" and answer[0] > 1:
answer[0] -= 1
elif commands[i] == "D" and answer[0] < n:
answer[0] += 1
return answer
n = 5
commands = "RRRUDD"
ret = robot_move(n, commands)
print(ret)
To embed this project on your website, copy the following code and paste it into your website's HTML: