import java.io.File fun main(args: Array){ 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") }