

I think I got pretty lucky that the Java library I used was pretty straightforward and had good docs.
This was definitely an unfulfilling way to solve a puzzle. I did take linear algebra in college, but I really struggled in that class and retained none of it.


Kotlin
Looking at the puzzle, I knew that I had no clue how to solve it. So I came here to see if I was missing something or if there were any hints.
And the hint I saw was to do the simplest check possible, so I gave it a shot.
And that got the test input wrong, but I ran it against the real input anyway just to see if it was right. And it was.
I think if I had gone on my instincts and just tried to solve this, I could have gone around in circles for hours or days trying to get it right.
fun main() { val input = getInput(12) val (gifts, regions) = parseInput1(input) var total = 0 for (i in regions.indices) { val totalAreaOfGifts = regions[i].gifts.mapIndexed { index, count -> count * gifts[index].area }.sum() if (totalAreaOfGifts <= regions[i].area) { total++ } } println(total) } data class Gift(val shape: List<List<Char>>, val area: Int) data class Region(val width: Int, val height: Int, val area: Int, val gifts: List<Int>) fun parseInput1(input: String): Pair<List<Gift>, List<Region>> { val gifts: MutableList<Gift> = mutableListOf() val regions: MutableList<Region> = mutableListOf() val lines = input.lines() lines.forEachIndexed { index, line -> if (line.contains(":")) { if (line.contains("x")) { val split = line.split(" ") val shape = split.first().replace(":", "").split("x") val width = shape.first().toInt() val height = shape.last().toInt() regions.add( Region( width, height, width * height, split.slice(1..<split.size).map { str -> str.toInt() }) ) } else { var nextBlankLineIndex = 0 for (i in index + 1..<lines.size) { if (lines[i].isBlank()) { nextBlankLineIndex = i break } } val shape = lines.slice(index + 1..<nextBlankLineIndex).map { it.toCharArray().toList() } val area = shape.flatten().filter { it == '#' }.size gifts.add(Gift(shape, area)) } } } return gifts to regions }