City Grid Distance
Manhattan distance is like walking through a city grid: you can move horizontally and vertically, but not diagonally. Given two points (x1, y1) and (x2, y2), return the distance between them using abs(x1 - x2) + abs(y1 - y2). This is useful for maps, grid-based games, and route calculations on rectangular layouts.
Примеры
Ввод
0, 0, 3, 4Вывод
7Ввод
1, 1, 1, 1Вывод
0Ввод
-2, -3, 2, 3Вывод
10Нужно реализовать
def manhattan(x1, y1, x2, y2):
Теги
math
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 isteachTests12
Visible tests
Tástáil fholaithe 7
Tástáil fholaithe 8
Tástáil fholaithe 9
Tástáil fholaithe 10
Tástáil fholaithe 11
Tástáil fholaithe 12
They run when you press "Submit" — your whole solution is checked against them so you can't hard-code answers for the visible cases.
Focus radio
Paused · SomaFM · Fluid