2018-07-26 Bits, Please! Code Fight
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
def perfectCity(departure, destination) | |
diff(departure[0], destination[0]) + diff(departure[1], destination[1]) | |
end | |
def diff(dep, dest) | |
naiveDiff = (dep - dest).abs | |
extraDiff = 0 | |
if dep.ceil == dest.ceil | |
lower, higher = [dep, dest].sort | |
extraDiff = [lower - lower.floor, higher.ceil - higher].min * 2 | |
end | |
naiveDiff + extraDiff | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment