Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2018-07-26 Bits, Please! Code Fight
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