Skip to content

Instantly share code, notes, and snippets.

@4RSIM3R
Created September 26, 2023 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 4RSIM3R/a93d2605e34ed78bf5e075bf6c3d15ce to your computer and use it in GitHub Desktop.
Save 4RSIM3R/a93d2605e34ed78bf5e075bf6c3d15ce to your computer and use it in GitHub Desktop.
[PHP] Manhattan Distance
<?php
// Manhattan Distance :
// Buatlah sebuah fungsi untuk menghitung 'manhattan distance' antara 2 titik koordinat, contoh:
//
// A = (2, 2)
// B = (3, 5)
//
// |x1 - x2| + |y1 - y2|
//
// Berapa Manhattan Distance Nya ? |2 - 3| + |2 - 5| -> |-1| + |-3| -> 1 + 3 = 4
function manhattanDistance($x1, $y1, $x2, $y2) {
}
$result1 = manhattanDistance(2, 2, 3, 5);
echo $result1; // 4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment