Skip to content

Instantly share code, notes, and snippets.

@DaneWeber
Created July 26, 2018 15:15
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 DaneWeber/0429cc31407263a485414d32017bcdc2 to your computer and use it in GitHub Desktop.
Save DaneWeber/0429cc31407263a485414d32017bcdc2 to your computer and use it in GitHub Desktop.
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