From 9e8f49963c16239429cb492fd83817e34555f533 Mon Sep 17 00:00:00 2001 From: Sven Weidauer Date: Wed, 11 Dec 2024 21:01:45 +0100 Subject: [PATCH] Day 11 Part 1 --- 2024/src/main/kotlin/day11.kt | 31 +++++++++++++++++++++++++++++++ 2024/src/main/resources/day11.txt | 1 + 2 files changed, 32 insertions(+) create mode 100644 2024/src/main/kotlin/day11.kt create mode 100644 2024/src/main/resources/day11.txt diff --git a/2024/src/main/kotlin/day11.kt b/2024/src/main/kotlin/day11.kt new file mode 100644 index 0000000..d964150 --- /dev/null +++ b/2024/src/main/kotlin/day11.kt @@ -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.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) + } +} \ No newline at end of file diff --git a/2024/src/main/resources/day11.txt b/2024/src/main/resources/day11.txt new file mode 100644 index 0000000..30ca9cc --- /dev/null +++ b/2024/src/main/resources/day11.txt @@ -0,0 +1 @@ +3 386358 86195 85 1267 3752457 0 741 \ No newline at end of file