<Advent of Code 2023 day 22> :thread:
# advent-of-code
a
e
Hint: use z-buffer
b
i've no experience with z-buffer but its pretty straightforward using 3d points, its just a bit more coding than most problems
of course i say that and am getting the wrong answer on p2 even though it works with the example fine 😕
j
@bj0 did you think about bricks falling if their supporting brick is falling?
b
yea, if you don't, the example doesn't work
j
I personally kept a list of bricks supported by the brick and updated that, to count how many would fall
b
i have a map of brick -> bricks it supports, and im using a bfs to walk the map removing unsupported bricks
j
My part 2 code is an absolute mess with a do while loop, I'm not really happy about that
b
mines relatively clean, which is making my head hurt since i can't find my bug
j
clean code and bug screams to me there is a logic issue in there
b
yea i've re-read the problem and my code over and over
it seems simple
it would really help if the example wasn't working
oh i think i see the issue
ah yea that was it
d
I have a very slow solution for part 2 where I just remove all the cubes which are the sole support for cubes above it, then let gravity do its work and count the moved cubes above 😅 Slow (~2m), but correct. Now optimize.
j
@daugian that kinda is what I first tried, except that after 30mins it had not computed a result, so I optimized
e
Once you have a list of supporting bricks for each brick (I add -1 for bricks supported by the ground), then “do while changes” is a nice, clean and fast-working way to build a set of disintegrating bricks. Nothing fancier is really needed. https://github.com/elizarov/AdventOfCode2023/blob/288847a62b94bf3a3aed9b7a2ca24aa71072794c/src/Day22_2.kt#L47
w
I used a graph approach (incoming and outgoing dependencies, similar to topological sort), basically the blocks above and below. Runs very fast: https://github.com/werner77/AdventOfCode/blob/master/src/main/kotlin/com/behindmedia/adventofcode/year2023/day22/Day22.kt
slightly vexed that I can't
Copy code
val (a, b, c, d, e, f) = line.split(',', '~')
j
oh component6 is not in the standard lib. Have to say I normally only need 2-3 components, which I think is fair. I solved that with
Copy code
val (left, right) = split("~")
    .map {
        it.split(",")
            .map { n -> n.toInt() }
            .let { (x, y, z) -> Point3D(x, y, z) }
    }
👍 1
m
https://github.com/mdekaste/AdventOfCode2023/blob/master/src/main/kotlin/day22/Day22.kt Standard~ish implementation. Sort the points, want to do the 'settling down' more efficient later. other than that, my "Brick" class does most of the heavy lifting today
m
Standard~ish implementation
Same... Part 1 took embarrassingly long until I found a bug, which led to counting some bricks multiple times https://github.com/fabmax/aoc-2023/blob/main/src/main/kotlin/day22/Day22.kt
👍 1
In case anybody was wondering...
🤩 1
K 3
😍 7
🔥 1
n
Piece of cake, both parts worked on the first try. Nice respite after Day 21, which I still haven't figured out Part 2 for.
Bricks are magically stabilized, so they never rotate, even in weird situations like where a long horizontal brick is only supported on one end.
I was almost certain that this condition would change for part 2, but I'm glad it didn't!
j
Oh yeah I kinda feared that to, but I thought the wording in here suggested, we would have to remove exactly those, that are not safe to disintegrate
Your first task is to figure out which bricks are safe to disintegrate. A brick can be safely disintegrated if, after removing it, no other bricks would fall further directly downward.
m
can you imagine if the puzzle description actually said something like: "When less than half of a piece is supported, it flips on its side, falling further down"
Im getting shivers already
k
Ended up doing this a completely different way than how I started. Took too long and I had to drop it several times, but quite happy with the eventual solution: https://github.com/kingsleyadio/adventofcode/blob/main/src/com/kingsleyadio/adventofcode/y2023/Day22.kt
v
A compact 37-line solution using a Kotlin sequence for non-recursive traversal of supporters graph: https://github.com/vkopichenko/Contests/blob/main/adventofcode/src/2023/y23day22part2.kt