aboutsummaryrefslogtreecommitdiff
path: root/aoc-2021-kotlin/src/Day01.kt
blob: 4ac1ef7bdbd857b2638440642f56d41532fd6165 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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))
}