hoshom
2021-12-19 11:41:22

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


massung
2021-12-19 15:48:33

Day 19 spoilers


massung
2021-12-19 15:49:24

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.


massung
2021-12-19 16:26:29

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.


badkins
2021-12-19 17:51:29

<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!


badkins
2021-12-19 17:54:02

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.


badkins
2021-12-19 17:54:52

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 :)


badkins
2021-12-19 17:55:53

@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 (-&gt;list obj)))


massung
2021-12-19 17:56:26

lol


badkins
2021-12-19 17:56:54

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


badkins
2021-12-19 17:59:01

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 :)


badkins
2021-12-19 18:00:47

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


massung
2021-12-19 18:02:36

wait until you do day 19 :stuck_out_tongue:


badkins
2021-12-19 18:11:03

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.


badkins
2021-12-19 18:12:20

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 :)


badkins
2021-12-19 18:13:07

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 …


massung
2021-12-19 18:41:36

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.


ben.knoble
2021-12-19 19:45:08

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


badkins
2021-12-20 02:17:15

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


badkins
2021-12-20 02:19:26

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


badkins
2021-12-20 02:20:51

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


massung
2021-12-20 03:48:58

> 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?