Fix 2018/2/2 solution

This commit is contained in:
Aly 2018-12-01 21:22:51 -08:00
parent 1968911351
commit 30fad2d678
No known key found for this signature in database
GPG key ID: 555B7346639DDAC3

View file

@ -14,9 +14,9 @@ object Day02 extends Day {
override def part2(input: String): String = { override def part2(input: String): String = {
val lines = input.lines.toList val lines = input.lines.toList
val distanceMap = lines.flatMap(s => lines.map(c => ((s, c), levenshtein(s, c)))).toMap val distanceMap = lines.flatMap(s => lines.map(c => ((s, c), s.intersect(c)))).toMap
val ((s, c), _) = distanceMap.filter {case (_, d) => d > 0 }.minBy { case (_, d) => d } val (_, r) = distanceMap.filter { case ((a, _), d) => d.length != a.length }.maxBy { case (_, d) => d.length }
s.intersect(c).mkString r.mkString
} }
} }