From 30fad2d6788cbcc7ceb64675ffc59357b0149347 Mon Sep 17 00:00:00 2001 From: Soren Date: Sat, 1 Dec 2018 21:22:51 -0800 Subject: [PATCH] Fix 2018/2/2 solution --- aoc/src/main/scala/aoc/y2018/Day02.scala | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/aoc/src/main/scala/aoc/y2018/Day02.scala b/aoc/src/main/scala/aoc/y2018/Day02.scala index 573cba8..b08d991 100644 --- a/aoc/src/main/scala/aoc/y2018/Day02.scala +++ b/aoc/src/main/scala/aoc/y2018/Day02.scala @@ -14,9 +14,9 @@ object Day02 extends Day { override def part2(input: String): String = { val lines = input.lines.toList - val distanceMap = lines.flatMap(s => lines.map(c => ((s, c), levenshtein(s, c)))).toMap - val ((s, c), _) = distanceMap.filter {case (_, d) => d > 0 }.minBy { case (_, d) => d } - s.intersect(c).mkString + val distanceMap = lines.flatMap(s => lines.map(c => ((s, c), s.intersect(c)))).toMap + val (_, r) = distanceMap.filter { case ((a, _), d) => d.length != a.length }.maxBy { case (_, d) => d.length } + r.mkString } }