generated from Jadarma/advent-of-code-kotlin-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathY2022D01.kt
25 lines (21 loc) · 773 Bytes
/
Y2022D01.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
package aockt.y2022
import io.github.jadarma.aockt.core.Solution
object Y2022D01 : Solution {
/** Parse the input and return a list containing the total calories of each elf at a given index. */
private fun parseInput(input: String): List<Int> = buildList {
var index = 0
var calories = 0
input.lineSequence().forEach { line ->
if (line.isBlank()) {
add(index, calories)
index += 1
calories = 0
} else {
calories += line.toInt()
}
}
add(index, calories)
}
override fun partOne(input: String) = parseInput(input).max()
override fun partTwo(input: String) = parseInput(input).sortedDescending().take(3).sum()
}