Created
April 20, 2016 10:15
-
-
Save sword-jin/b0625fc4335c117645d8b97a9c32e5e5 to your computer and use it in GitHub Desktop.
Uber prefect city
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function perfectCity($departure, $destination) { | |
$length = 0; | |
if ((int) $destination[1] == (int) $departure[1]) { | |
$length += min([1 - $departure[1] - (int) $departure[1] + 1 - $destination[1] - (int) $destination[1], $destination[1] - (int) $destination[1] + $departure[1] - (int) $departure[1]]); | |
} else { | |
$length += $destination[1] - $departure[1]; | |
} | |
if ((int) $destination[0] == (int) $departure[0]) { | |
$length += min([1 - $departure[0] - (int) $departure[0] + 1 - $destination[0] - (int) $destination[0], $destination[0] - (int) $destination[0] + $departure[0] - (int) $departure[0]]); | |
} else { | |
$length += $destination[0] + $departure[0]; | |
} | |
return $length; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test 3/5