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
Logga in för att se historik över inskick
Logga inLogga in för att använda AI-mentorn
Logga inVisible tests
1
Input
0, 0, 3, 4Expected
72
Input
1, 1, 1, 1Expected
03
Input
-2, -3, 2, 3Expected
104
Input
5, 0, 0, 5Expected
105
Input
10, -10, -10, 10Expected
406
Input
5, 999999, 0, 5Expected
999999Focus radio
Paused · SomaFM · Fluid