From d394c8697f020f0b90f6a0d0fc53934ae921a1a8 Mon Sep 17 00:00:00 2001 From: Hubert Van De Walle Date: Sat, 5 Dec 2020 08:18:25 +0100 Subject: [PATCH] Sort once --- days/src/main/kotlin/Day05.kt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/days/src/main/kotlin/Day05.kt b/days/src/main/kotlin/Day05.kt index 6f24c05..8a1d794 100644 --- a/days/src/main/kotlin/Day05.kt +++ b/days/src/main/kotlin/Day05.kt @@ -14,12 +14,11 @@ class Day05(@Lines val input: Input>) { .replace("L", "0") .replace("R", "1") .toInt(2) - } + }.sorted() - fun part1() = ids.maxOrNull() + fun part1() = ids.last() - fun part2() = ids.sorted() - .windowed(size = 2, step = 1) + fun part2() = ids.windowed(size = 2, step = 1) .find { (a, b) -> b - a > 1 }!! .first() + 1 }