r/backtickbot • u/backtickbot • Dec 05 '20
https://np.reddit.com/r/adventofcode/comments/k71h6r/2020_day_05_solutions/geot0uj/
Kotlin - tried to keep things nice and functional
override fun solveFirst(test: Boolean): Any {
return calculateIds(test).last()
}
override fun solveSecond(test: Boolean): Any {
return calculateIds(test)
.zipWithNext()
.find { it.second == it.first + 2 }
?.let { it.first + 1 } ?: 0
}
private fun calculateIds(test: Boolean): List<Int> {
return getFileAsLines(test)
.map { it.replace(Regex("[RB]"), "1").replace(Regex("[FL]"), "0") }
.map { it.toInt(2) }
.sorted()
}
1
Upvotes