popa.bogdanp
2021-12-18 09:43:40

Day 18


popa.bogdanp
2021-12-18 09:45:30

I tried really hard to come up with a functional solution, but got annoyed at how much time I was spending on the problem so I went w/ a solution that’s very mutation-heavy:

https://github.com/Bogdanp/aoc2021/blob/master/day18.rkt


massung
2021-12-18 15:55:37

Yep, mine mutates as well. Was going to do it last night, but read the puzzle at midnight and pretty much noped out of it. Didn’t feel like writing binary tree code that late.

https://github.com/massung/advent2021/blob/main/day18/day18.lisp

One thing that sucks about the mutation is that is makes part 2 slower since you either have to copy trees or re-parse (I did the latter) for each addition.


ben.knoble
2021-12-18 17:56:19

I found one possible (maybe clever) functional representation that I think sped things up for me; rather than a binary tree, I used a list of element values and depth in the tree (it is, miraculously, possible to reconstruct the binary tree, at least for well-formed such lists). Part1 was ~70ms, Part2 ~1.2s. https://github.com/benknoble/advent2021/blob/main/day18/solution.rkt