
Software Developer at @JetBrains. Develop @Kotlin core libraries. Competitive programming enthusiast. Formula 1 fan. Coffee geek. Views are my own.
- Tweets3.3K
- Following403
- Followers914
- Likes5.6K
![package day05 import kodvent.graph.bfs class Day05 { fun part1(buttons: List<String>): Int = bfs(0, maxDistance = 3) { display -> buttons.map { it.push(display) } }.keys.sum() fun part2(buttons: List<String>): Int = bfs(0) { display -> buttons.map { it.push(display) }.filter { it < 10_000 } }.keys.sum() private fun String.push(display: Int): Int { val label = removeSurrounding("[", "]") return when { label == "oct" -> display.toString(8).toInt() label == "bksp" -> display / 10 label.startsWith('*') -> display * label.drop(1).toInt() label.startsWith('/') -> display / label.drop(1).toInt() "->" in label -> label.split("->").let { (from, to) -> "$display".replace(from, to).toInt() } else -> "$display$label".toInt() } } }](https://pbs.twimg.com/media/HYy_SoIXkAA3aDW.jpg?name=small&format=webp)
ALT package day05 import kodvent.graph.bfs class Day05 { fun part1(buttons: List<String>): Int = bfs(0, maxDistance = 3) { display -> buttons.map { it.push(display) } }.keys.sum() fun part2(buttons: List<String>): Int = bfs(0) { display -> buttons.map { it.push(display) }.filter { it < 10_000 } }.keys.sum() private fun String.push(display: Int): Int { val label = removeSurrounding("[", "]") return when { label == "oct" -> display.toString(8).toInt() label == "bksp" -> display / 10 label.startsWith('*') -> display * label.drop(1).toInt() label.startsWith('/') -> display / label.drop(1).toInt() "->" in label -> label.split("->").let { (from, to) -> "$display".replace(from, to).toInt() } else -> "$display$label".toInt() } } }















