From 782d12c048ed779b9b14448120bc397f2620bf36 Mon Sep 17 00:00:00 2001 From: Chris Hodges Date: Wed, 4 Dec 2024 10:03:28 +0100 Subject: [PATCH] Very minor day 2 refinement. --- src/aoc2024/Day02.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/aoc2024/Day02.kt b/src/aoc2024/Day02.kt index 7c6a07a..af10497 100644 --- a/src/aoc2024/Day02.kt +++ b/src/aoc2024/Day02.kt @@ -50,21 +50,18 @@ fun main() { fun checkGood(i: List): Boolean { val dir = i[1] - i[0] return if (dir < 0) { - !i.runningReduce { acc, elem -> if ((elem < acc) and (elem >= acc - 3)) elem else Int.MIN_VALUE }.contains(Int.MIN_VALUE) + !i.runningReduce { acc, elem -> if ((elem < acc) and (elem >= acc - 3)) elem else Int.MIN_VALUE } + .contains(Int.MIN_VALUE) } else if (dir > 0) { - !i.runningReduce { acc, elem -> if ((elem > acc) && (elem <= acc + 3)) elem else Int.MAX_VALUE }.contains(Int.MAX_VALUE) + !i.runningReduce { acc, elem -> if ((elem > acc) && (elem <= acc + 3)) elem else Int.MAX_VALUE } + .contains(Int.MAX_VALUE) } else { false } } fun part1(input: List): Int { - val ilist = input.map { it.splitInts() } - var sum = 0 - for (i in ilist) { - if (checkGood(i)) sum++ - } - return sum + return input.map { it.splitInts() }.count(::checkGood) } fun part2(input: List): Int {