Move the Robot
A robot stands on a coordinate grid at (x, y) and faces one of four directions: N, E, S, or W. The function move receives a command string commands: L turns the robot left, R turns it right, and A moves it one step forward. Run all commands in order and return the robot’s new state as [x, y, direction].
Примеры
Ввод
0, 0, "N", ""Вывод
[0, 0, "N"]Ввод
0, 0, "N", "R"Вывод
[0, 0, "E"]Ввод
0, 0, "N", "L"Вывод
[0, 0, "W"]Нужно реализовать
def move(x: int, y: int, direction: str, commands: str) -> list:
Теги
strings
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteachVisible tests
1
Input
0, 0, "N", ""Expected
[0,0,"N"]2
Input
0, 0, "N", "R"Expected
[0,0,"E"]3
Input
0, 0, "N", "L"Expected
[0,0,"W"]4
Input
0, 0, "N", "A"Expected
[0,1,"N"]5
Input
7, 3, "N", "RAALAL"Expected
[9,4,"W"]6
Input
0, 0, "S", "EEEEE"Expected
[0,0,"S"]Focus radio
Paused · SomaFM · Fluid