Im finding the distance between two points, given departure = [x,y] and destination = [x,y]. With x or y, one is always a float and the other an int, so its always on a line. You have to stay on the gridlines to get to the destination point, and there is no set incrementation. I havent seen any other posts on finding distance on a grid that deal with the mix of ints and floats so here I am.
This is my code:
def perfectCity(departure, destination):
return abs(destination[0]-departure[0]) + abs(destination[1]-departure[1])
An example would be departure = [0.4, 1] and destination = [0.9, 3], it should equal 2.7, but I get 2.5
For example, you go from [0.4, 1] to [1, 1] to [1, 3] to [0.9, 3] for a total difference of 2.7. It's like calculating the Manhattan distance, but instead of starting and ending at lattice points, you might start and/or end half-way down a block.