changeset 12:a991288f3d55 tip @

day 11: simplify hexNorm
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Mon, 11 Dec 2017 22:24:25 -0500
parents 66707d1400b4
children
files 2017/day11.d
diffstat 1 files changed, 2 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/2017/day11.d
+++ b/2017/day11.d
@@ -1,7 +1,7 @@
 import std.array: array;
 import std.math: abs;
 import std.string: chomp, split;
-import std.algorithm: min, map, cumulativeFold, maxElement;
+import std.algorithm: max, map, cumulativeFold, maxElement;
 import std.stdio;
 
 immutable int[2][string] directions;
@@ -21,9 +21,7 @@
   if (x*y < 0) {
     return abs(x) + abs(y);
   }
-  x = abs(x);
-  y = abs(y);
-  return abs(x - y) + min(x, y);
+  return max(abs(x), abs(y));
 }
 
 void main(string[] args) {