Skip to content

Instantly share code, notes, and snippets.

@kid-cavaquinho
Created November 7, 2022 09:50
Show Gist options
  • Save kid-cavaquinho/a5772b820fcfc296e6cc889ffa35fc05 to your computer and use it in GitHub Desktop.
Save kid-cavaquinho/a5772b820fcfc296e6cc889ffa35fc05 to your computer and use it in GitHub Desktop.
// The Manhattan distance between two points is the sum of absolute difference of the coordinates.
static int Resolve(int M, int N, int X1, int Y1, int X2, int Y2)
{
return Math.Abs(X2 - X1) + Math.Abs(Y2 - Y1);
}
public static void Main()
{
// Define size of 2-D array
int M = 5, N = 5;
// First point
int X1 = 1, Y1 = 2;
// Second point
int X2 = 3, Y2 = 3;
Console.WriteLine(Resolve(M, N, X1, Y1, X2, Y2));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment