From 34c2414304d59e76d52b96efe6bebebb4e75f086 Mon Sep 17 00:00:00 2001 From: tchojnacki Date: Thu, 11 Aug 2022 12:01:44 +0200 Subject: Move year 2021 into a subfolder --- 2021-kotlin/src/Day01.kt | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 2021-kotlin/src/Day01.kt (limited to '2021-kotlin/src/Day01.kt') diff --git a/2021-kotlin/src/Day01.kt b/2021-kotlin/src/Day01.kt new file mode 100644 index 0000000..4ac1ef7 --- /dev/null +++ b/2021-kotlin/src/Day01.kt @@ -0,0 +1,24 @@ +object Day01 { + fun part1(input: List) = + input + .zipWithNext() + .count { it.second > it.first } + + fun part2(input: List) = + input + .asSequence() + .windowed(3) + .map { it.sum() } + .zipWithNext() + .count { it.second > it.first } +} + +fun main() { + val testInput = readInputAsNumbers("Day01_test") + check(Day01.part1(testInput) == 7) + check(Day01.part2(testInput) == 5) + + val input = readInputAsNumbers("Day01") + println(Day01.part1(input)) + println(Day01.part2(input)) +} -- cgit v1.2.3