From 817ef2dcfb3eea6b7f3972235101c74a8753be1c Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Mon, 11 Dec 2017 12:13:20 +0100 Subject: [PATCH] Handle edge case of sgn(x) != sgn(y) --- 2017/day-11/solution.scala | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/2017/day-11/solution.scala b/2017/day-11/solution.scala index a293af2..cd715c0 100644 --- a/2017/day-11/solution.scala +++ b/2017/day-11/solution.scala @@ -32,6 +32,10 @@ object solution { } def dist(x: Int, y: Int): Int = { - return Math.max(x, y); + if (x.signum == y.signum) { + return Math.max(x.abs, y.abs); + } else { + return x.abs + y.abs + } } }