my-solutions/advent-of-code-2023/01/part-1/main.kt

24 lines
456 B
Kotlin
Raw Normal View History

package main
import java.io.File
fun main() {
var sum = 0
File("../input.txt").forEachLine{
var firstDigit = ""
var lastDigit = ""
for (c in it) {
if (c.isDigit()) {
lastDigit = c.toString()
if (firstDigit == "") {
firstDigit = c.toString()
}
}
}
sum += (firstDigit + lastDigit).toInt()
}
println(sum)
}