Day 11 Part 1
This commit is contained in:
parent
fb7549498e
commit
9e8f49963c
2 changed files with 32 additions and 0 deletions
31
2024/src/main/kotlin/day11.kt
Normal file
31
2024/src/main/kotlin/day11.kt
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
1
2024/src/main/resources/day11.txt
Normal file
1
2024/src/main/resources/day11.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
3 386358 86195 85 1267 3752457 0 741
|
Loading…
Add table
Reference in a new issue