Compare commits
No commits in common. "2b3549c84c322f618b3ac797696df518a6834384" and "f51f87736b6bf86bf9142194951518522ed0d706" have entirely different histories.
2b3549c84c
...
f51f87736b
@ -1,56 +0,0 @@
|
|||||||
package aoc2025
|
|
||||||
|
|
||||||
import println
|
|
||||||
import readInput
|
|
||||||
import splitLongs
|
|
||||||
|
|
||||||
/*
|
|
||||||
--- Day 6: Trash Compactor ---
|
|
||||||
https://adventofcode.com/2025/day/6
|
|
||||||
*/
|
|
||||||
fun main() {
|
|
||||||
|
|
||||||
val inlineTestInput = """
|
|
||||||
123 328 51 64
|
|
||||||
45 64 387 23
|
|
||||||
6 98 215 314
|
|
||||||
* + * +
|
|
||||||
"""
|
|
||||||
|
|
||||||
fun part1(input: List<String>): Long {
|
|
||||||
val numbers = input.dropLast(1).map { it.splitLongs().toLongArray() }.toList()
|
|
||||||
val ops = input.last().split(" ").filter(String::isNotBlank)
|
|
||||||
return ops.withIndex().sumOf { (c, op) -> if (op == "+") numbers.sumOf { it[c] } else numbers.fold(1L) { acc, row -> acc * row[c] } }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun part2(input: List<String>): Long {
|
|
||||||
val numbers = ArrayList<LongArray>()
|
|
||||||
val maxLineLength = input.maxOf { it.length }
|
|
||||||
val spaceMask = BooleanArray(maxLineLength)
|
|
||||||
input.forEach { it.withIndex().filter { (_, ch) -> ch != ' ' }.forEach { (c, _) -> spaceMask[c] = true } }
|
|
||||||
val numColl = ArrayList<Long>()
|
|
||||||
for (c in 0 until maxLineLength) {
|
|
||||||
if (spaceMask[c]) numColl.add(input.dropLast(1).map { it[c] }.joinToString("").trim().toLong())
|
|
||||||
if (!spaceMask[c] || c == maxLineLength - 1) {
|
|
||||||
numbers.add(numColl.toLongArray())
|
|
||||||
numColl.clear()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return input.last().split(" ").filter(String::isNotBlank).withIndex()
|
|
||||||
.sumOf { (c, op) -> if (op == "+") numbers[c].sum() else numbers[c].fold(1L) { acc, row -> acc * row } }
|
|
||||||
}
|
|
||||||
|
|
||||||
// test if implementation meets criteria from the description, like:
|
|
||||||
val testInput = inlineTestInput.trim().reader().readLines()
|
|
||||||
//val testInput = readInput("aoc2025/Day06_test")
|
|
||||||
val testInputPart1Result = part1(testInput)
|
|
||||||
println("Part 1 Test: $testInputPart1Result")
|
|
||||||
val testInputPart2Result = part2(testInput)
|
|
||||||
println("Part 2 Test: $testInputPart2Result")
|
|
||||||
check(testInputPart1Result == 4277556L)
|
|
||||||
check(testInputPart2Result == 3263827L)
|
|
||||||
|
|
||||||
val input = readInput("aoc2025/Day06")
|
|
||||||
part1(input).println()
|
|
||||||
part2(input).println()
|
|
||||||
}
|
|
||||||
@ -69,7 +69,7 @@ class Downloader(val year: Int, val packageName: String, val sessionCookie: Stri
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
while (day == lastDay && LocalTime.now(ZoneId.of("UTC+1")).hour == 5) {
|
while (day == lastDay && LocalTime.now(ZoneId.of("UTC+1")).hour == 5) {
|
||||||
println("Waiting for puzzle to become available...")
|
println("Waiting until puzzle is available...")
|
||||||
runBlocking {
|
runBlocking {
|
||||||
if (LocalTime.now(ZoneId.of("UTC+1")).minute < 59) {
|
if (LocalTime.now(ZoneId.of("UTC+1")).minute < 59) {
|
||||||
delay(1.minutes)
|
delay(1.minutes)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user