
I used mutation too. @massung I quite like your solution, wish I’d thought of keeping a link back to the parent node. I basically kept a stack of boxes for “explode”, and on encountering the depth–4 node I mutate the top box. And the other thing I enjoyed doing was I basically wrote just the traversal code, and then wrote a couple functions called !
and x!
that I mutated during traversal. Not sure if it’s readable… At first I thought it was, not sure now though :smile: https://github.com/hashimmm/adventofcode/blob/master/2021/day18.rkt

Day 19 spoilers

https://github.com/massung/advent2021/blob/main/day19/day19.lisp
Waited until the morning again for this one. There are a couple things I don’t like about the solution, and it’s mostly brute force with a few minor optimizations thrown in there.

The difficult part - to me - was in trying to figure which beacons to align two scanners on. Currently I just have a stupid n^2 - for each beacon in A, try lining it up with every beacon in rotated(B) - and see if the other beacons also align.
That’s definitely the slow part of my code, and I’ve been trying to think through a better solution to that one piece.

<https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day18/day18.rkt|Day 18> - this was harder than it should’ve been for me!

I originally went with 3 structs, but then I found using only one made it simpler to switch between types by just setting the fields.

I also considered a functional approach, but in addition to being harder to code, I knew it would also be slower, so I wasn’t super motivated to try it :)

@massung got a kick out of your “you either have to copy trees or re-parse” statement, because here’s my copy-node
:) (define (copy-node obj)
(parse-snail (->list obj)))

lol

I actually started coding a proper copy-node
, then said, bah :)

Nice solution @ben.knoble - in the past, it seems the qi
solutions have been more verbose, but this time it certainly beat my “plain vanilla” code :)

This may be the least pleased I’ve been with my solution thus far - but there’s still time to reach a new low! :)

wait until you do day 19 :stuck_out_tongue:

I mentioned this in our local slack already, but I’ve been doing functional programming for so long, I was unprepared for some really tricky mutation-related bugs for Day 18. The last one was realizing I had to copy nodes for part 2 ! :) Having said that, I’d still probably use mutation to solve something like this in production code.

I always check the leaderboard to see the time of the top & 100th person to get a feel for the difficulty. Day 19 ranges from 21 minutes to 65 minutes, so I’m guessing it’ll be hard :)

Although, that can be counter-intuitive - sometimes it just means there wasn’t a clever trick available, so people did something closer to my solution - we’ll see for Day 19 …

I question the global leaderboard. There are times when the time it took for the top 1–3 people to complete it is less time than it took me to read the question, which seems suspect. But, I try not to focus on it too much.

I’m looking at relative distances between nodes a beacon sees. Then it’s (slightly) easier to pair up (pairs of) beacons based on matching relative distances

<https://github.com/lojic/LearningRacket/blob/master/advent-of-code–2021/solutions/day19/day19.rkt|Day 19>

@ben.knoble that seems like a similar “big O” though, right?

This puzzle never really inspired me to do better than a simplistic solution, but maybe there was a nice general solution I missed.

> I’m looking at relative distances between nodes a beacon sees. Ditto, but you need a point of reference to start from since not all the scanners see the same beacons. Or are you saying that if 12 relative distances are the same then it’s a match? I could see that, but then what information are you using to compute the relative distance between the two scanners?