-
Notifications
You must be signed in to change notification settings - Fork 0
/
9b.kt
32 lines (30 loc) · 852 Bytes
/
9b.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
import kotlin.io.path.Path
import kotlin.io.path.readLines
import kotlin.math.*
fun <T> debug(container: Iterable<T>) {
container.forEach { element -> print("$element ") }
println()
}
fun main() {
val fileName = "9.in"
val input = Path(fileName).readLines()
var result = 0
for (line in input) {
val firstRow = line.split(" ").map { it.toInt() }.toMutableList()
var levels = mutableListOf(firstRow)
while (true) {
var newRow = mutableListOf<Int>()
for (i in 1 until levels.last().size) {
newRow += levels.last()[i] - levels.last()[i-1]
}
levels += newRow
if (newRow.all { it == 0 }) break
}
levels.last() += 0
for (i in levels.size-2 downTo 0) {
levels[i].add(0, levels[i].first() - levels[i+1].first())
}
result += levels.first().first()
}
println(result)
}