-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay1.kt
32 lines (25 loc) · 947 Bytes
/
Day1.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
package aoc2021.day01
fun findIncreasingDepthValues(inputList: List<Int>): Int {
var increasingDepthCount = 0
var currentDepthValue = inputList[0]
inputList.subList(1, inputList.size).forEach { depthValue ->
if (depthValue > currentDepthValue) {
increasingDepthCount++
}
currentDepthValue = depthValue;
}
return increasingDepthCount
}
fun findIncreasingThreeMeasurementDepthValues(inputList: ArrayList<Int>): Int {
var increasingDepthCount = 0
var currentThreeMeasurementDepthValue = inputList.take(3).sum()
while (inputList.isNotEmpty()) {
inputList.removeFirst()
val threeMeasurementDepthValue = inputList.take(3).sum()
if (threeMeasurementDepthValue > currentThreeMeasurementDepthValue) {
increasingDepthCount++
}
currentThreeMeasurementDepthValue = threeMeasurementDepthValue
}
return increasingDepthCount;
}