Skip to content

Instantly share code, notes, and snippets.

@sword-jin
Created April 20, 2016 10:15
Show Gist options
  • Save sword-jin/b0625fc4335c117645d8b97a9c32e5e5 to your computer and use it in GitHub Desktop.
Save sword-jin/b0625fc4335c117645d8b97a9c32e5e5 to your computer and use it in GitHub Desktop.
Uber prefect city
<?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;
}
@haisaco
Copy link

haisaco commented Apr 5, 2017

test 3/5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment