From fbdd2f6aaf331c96176f4bd6684a77b80e188bf6 Mon Sep 17 00:00:00 2001 From: tchojnacki Date: Wed, 1 Dec 2021 20:43:04 +0100 Subject: Complete day 1 --- src/Day01.kt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Day01.kt b/src/Day01.kt index 35b4e09..7503c69 100644 --- a/src/Day01.kt +++ b/src/Day01.kt @@ -1,15 +1,22 @@ fun main() { - fun part1(input: List): Int { - return input.size - } + fun part1(input: List): Int = + input + .map { it.toInt() } + .zipWithNext() + .count { it.second > it.first } - fun part2(input: List): Int { - return input.size - } + fun part2(input: List): Int = + input + .asSequence() + .map { it.toInt() } + .windowed(3) + .map { it.sum() } + .zipWithNext() + .count { it.second > it.first } - // test if implementation meets criteria from the description, like: val testInput = readInput("Day01_test") - check(part1(testInput) == 1) + check(part1(testInput) == 7) + check(part2(testInput) == 5) val input = readInput("Day01") println(part1(input)) -- cgit v1.2.3