diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Day01.kt | 23 |
1 files changed, 15 insertions, 8 deletions
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<String>): Int { - return input.size - } + fun part1(input: List<String>): Int = + input + .map { it.toInt() } + .zipWithNext() + .count { it.second > it.first } - fun part2(input: List<String>): Int { - return input.size - } + fun part2(input: List<String>): 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)) |