diff options
author | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
---|---|---|
committer | tchojnacki <tomaszchojnacki2001@gmail.com> | 2022-08-11 19:24:23 +0200 |
commit | 0f1e145b80813ae2331b7dac5ace0c589654ad2a (patch) | |
tree | 25483b8239436dd5aed2fee8811caf0ba893c0bb /aoc-2021-kotlin/src/Day01.kt | |
parent | 85fb0396bed6a2129b12392941103924b1ab55be (diff) | |
download | gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.tar.gz gleam_aoc2020-0f1e145b80813ae2331b7dac5ace0c589654ad2a.zip |
Move subproject to avoid IntelliJ module name issues
Diffstat (limited to 'aoc-2021-kotlin/src/Day01.kt')
-rw-r--r-- | aoc-2021-kotlin/src/Day01.kt | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/aoc-2021-kotlin/src/Day01.kt b/aoc-2021-kotlin/src/Day01.kt new file mode 100644 index 0000000..4ac1ef7 --- /dev/null +++ b/aoc-2021-kotlin/src/Day01.kt @@ -0,0 +1,24 @@ +object Day01 { + fun part1(input: List<Int>) = + input + .zipWithNext() + .count { it.second > it.first } + + fun part2(input: List<Int>) = + 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)) +} |