generated from kotlin-hands-on/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay01.kt
37 lines (31 loc) · 841 Bytes
/
Day01.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package year2021.`01`
import readInput
fun main() {
fun part1(input: List<String>): Int {
var count = 0
input
.map { it.toInt() }
.reduce { left, right ->
if (right > left) count++
right
}
return count
}
fun part2(input: List<String>): Int {
var count = 0
input
.map { it.toInt() }
.windowed(3, 1)
.reduce { left, right ->
if (right.sum() > left.sum()) count++
right
}
return count
}
// test if implementation meets criteria from the description, like:
val testInput = readInput("Day01_test")
check(part2(testInput) == 5)
val input = readInput("Day01")
println(part1(input))
println(part2(input))
}