AdventOfCode-2017/day9.kt

33 lines
984 B
Kotlin
Raw Permalink Normal View History

2020-12-04 18:01:27 -08:00
import java.io.File
fun main(args: Array<String>){
val line = File("../puzzle_9.txt").readLines().first()
// val line = "<!!!>>"
var indent = 0
var totalScore = 0
var currentIndex = 0
var garbage = 0
while(currentIndex < line.length) {
when {
line[currentIndex] == '{' -> indent++
line[currentIndex] == '<' -> {
while(currentIndex < line.length && line[currentIndex] != '>') {
if(line[currentIndex] != '!') {
garbage += 1
currentIndex += 1
} else {
currentIndex += 2
}
}
garbage -= 1
}
line[currentIndex] == '}' -> {
totalScore += indent
indent--
}
}
currentIndex++
}
println("The score is $totalScore")
println("The garbage amount is $garbage")
}