Day 11 Part 1

This commit is contained in:
Sven Weidauer 2024-12-11 21:01:45 +01:00
parent fb7549498e
commit 9e8f49963c
2 changed files with 32 additions and 0 deletions

View file

@ -0,0 +1,31 @@
fun main() {
val input = readInputString("day11.txt").split(" ").map { it.toLong() }
val part1 = (1..25).fold(input) { result, _ ->
result.blink()
}.count()
println("Part 1: $part1")
val part2 = (1..75).fold(input) { result, _ ->
result.blink()
}.count()
println("Part 2: $part2")
}
fun List<Long>.blink() = flatMap {
val str = "$it"
val strLen = str.count()
when {
it == 0L -> listOf(1L)
strLen % 2 == 0 -> listOf(
str.substring(0, strLen / 2).toLong(),
str.substring(strLen / 2).toLong()
)
else -> listOf(it * 2024)
}
}

View file

@ -0,0 +1 @@
3 386358 86195 85 1267 3752457 0 741