<Advent of Code 2025 day 12> (spoilers) :thread:
# advent-of-code
a
k
I don't like today at all.
💯 3
d
NP hard, what's the problem
v
This ended up being waaaaay simpler than it looked
🧠 1
d
Well like I see some number of my lines can fit with 0 need to pack because there are enough 3x3 grids for them
And then one shape can make a 4x3 grid with 2
Need to look at the shapes more closely
v
Hint: there's a shortcut
🧠 1
d
Alright I will exit spoiler chat for now 🙃
OMG LOL
same 2
Solve
😀 1
m
well... I kinda did the 'trick' to at least know beforehand to not check... I didn't know the predicate also worked the other way. 😂
I solved it the brute force way but the 'trick' way works as well. Wonder if there's a poor soul that it doesn't work for
d
Right my next step was going to be filter out based on that criteria, then “may as well check”
ah so actually. i had an error in the “3x3 fits” (> instead of >=). you can just see that working forward and backward give the same number, therefore there are no areas that need special packing
Screenshot 2025-12-11 at 10.56.19 PM.png
j
Oh soooo disappointing puzzle today 😞
p
I'm kinda disappointed so much of that wasn't needed 😞 I shouldn't have checked initial predicate 😞
Copy code
@AoKSolution
object Day12 {
    context(input: PuzzleInput)
    fun trees() =
        input.lines.mapNotNull {
            if (it.indexOf('x') != 2) return@mapNotNull null
            val dims = it.substringBefore(':').split('x').let { (a, b) -> a.toInt() to b.toInt() }
            val presents = it.substringAfter(' ').split(' ').map(String::toInt)
            dims to presents
        }

    context(_: PuzzleInput)
    fun part1() = trees().count { (dims, presents) -> presents.sum() * 9 <= dims.first * dims.second }
}
j
Copy code
data class Region(val w: Int, val h: Int, val counts: List<Int>) {
    fun pack(shapes: List<Shape>): Boolean {
        if (counts.sum() <= (w / 3) * (h / 3)) return true
            .debug { "Trivially fits by count" }
        if (shapes.zip(counts).sumOf { (s, n) -> n * s.size } > h * w) return false
            .debug { "Too much area needed" }

        val toGo = shapes.flatMapIndexed { index, shape -> List(counts[index]) { shape } }
            .debug { "To go: ${it.size} shapes" }
        TODO("Implement packing algorithm")
    }
}
I'm so sad I'll never do this
TODO()
😂 3
d
Modifying my code to add a TODO
advent of code intensifies 1
Saved 1 LOC in the process
j
Things I already implemented and won't be needed anyway: • parsing shapes (instead I could just say
data class(val size: Int =7)
• rotating and flipping shapes • pretty printing of shapes with all possible rotation/flipping cases, for debug purposes • half of the placement logic well, sorry to let it go, but:
d
My shapes had different # counts
j
my shapes were exactly the same as in puzzle's example
d
7 7 7 7 6 5 for me
j
oh damn. NO you're right, for me it was also different, I didn't check correctly open eye crying laughing . so even worse 🙂
m
WHAT
😂 1
I finished implementing all the rotations, the packing, recursive search with pruning, got it to work on the examples but it was too slow on the real data, came here for hints...
😭 1
p
you mean you did more than
Copy code
@AoKSolution
object Day12Min {
    context(_: PuzzleInput)
    fun part1() = lines.count {
        if('x' !in it) return@count false
        val ints = it.split("x", ": ", " ").map(String::toInt)
        ints.let { (x, y) -> x * y } >= ints.subList(2, ints.size).sum() * 9
    }
}
?
m
internal screaming
same 2
j
to be fair, this is safer:
Copy code
counts.sum() <= (w / 3) * (h / 3)
m
I'm so sad
😂 1
j
GOLFING TIME!
but frankly,
sumOf(9::times)
is such an abomination 🙂
m
I love me some function references
p
🏌️ 67 tokens
Copy code
fun main() = println(generateSequence(::readLine).count {
    Regex("\\D").split(it).mapNotNull(String::toIntOrNull)
        .run { size == 8 && let { (a, b) -> a * b / 9 >= sum() - a - b } }
})
"6 7" tokens fits the current zeitgeist nicely. I'll stop there.
nice spin 1
6️⃣ 1
7️⃣ 1
k
@phldavies can be shorter
Copy code
...
'x' in it && it.split(Regex("\\D+")).map { it.toInt() }
...
🏌️ 1
e
the proof it got me first:
b
but.. but.. i originally tried the easy answer that people are showing, but i tried it against the sample data first which it doesn't work against
so i didn't try it against my own data
j
And you’re not the only one
b
how rude of the example input
e
yeah took me so long to realize that the right approach doesn't work for the sample input...
j
The puzzle input was lame, but it was a good day for visualizations.
❤️ 1