fb pixel

Manhattan distance

The streets in the central part of Manhattan are constructed in a way that resembles a grid. To get from one crossroad you need to go parallel in one direction and then vertical in another. So, if we imagine a virtual X and Y axis, in Manhattan, we always move either parallel to the OX axis or parallel to the OY axis.
notion image
This construction of streets has become so popular that people started using it as a distance metric. When it’s only allowed to move in the OX or the OY directions and one needs to get from to , they first move parallel to the OX axis to get from to and afterward from to . This changes the calculations of distance between points and is called Manhattan distance. The standard Euclidean distance is .
Can you figure out the Manhattan distance between two points?
The input consists of 4 numbers: and coordinates of the first point followed by and coordinates of the second point. The program should output the Manhattan distance between those two points.
3 4 1 0.5
notion image
To check your solution you need to sign in
Sign in to continue