Fork me on GitHub
#adventofcode
<
2021-12-18
>
alekszelark04:12:45

🧵Day 18 Solutions Thread: post your solution here

norman07:12:24

https://gitlab.com/maximoburrito/advent2021/-/blob/main/src/day18/main.clj I also went with zippers, despite the fact that in my 8 or 9 years with Clojure I've never had cause to use them before. I almost gave up to switch to a mutable tree structure, but at the last second I found the problem I was having.

👍 2
nbardiuk09:12:19

flattened tree into vector of pairs of value and path https://github.com/nbardiuk/adventofcode/blob/master/2021/src/day18.clj

👏 2
nbardiuk09:12:16

zippers look cool :the_horns:

1
jacoelho18:12:20

Thank you for suggestion on zippers https://github.com/jacoelho/advent-of-code-clj/blob/main/src/aoc/2021/day18.clj Part 2 takes like 8seconds, is that expected or is an implementation issue?

kevinc18:12:39

https://github.com/kconner/advent-of-code/blob/master/2021/18a.cljhttps://github.com/kconner/advent-of-code/blob/master/2021/18b.clj. 1.2s and 3.3s. I did think this might be the kind of thing a zipper is good for, but i didn't research and use them this time. maybe I'll be inspired next time by having done it the hard way already 🙂

kevinc18:12:33

if you treat the index path to the node to be exploded as a four-bit binary number, you can find the leaf to either side by incrementing or decrementing that path number. if you overflow, you're out of the structure. then extend with a fifth bit for depth, and find the leaf on that path.

👌 1
Callum Oakley21:12:03

no zippers here, but it looks like it would be a good problem to revisit to give them a try… only interesting bit is explode, which walks the tree depth first and returns a triple of “left carry”, “exploded number”, “right carry”. which get carried back up the call stack and applied as appropriate. 21ms/160ms https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/18.clj

euccastro23:12:43

I had the feeling that something like zippers/lenses or other similar things I never learned about would be applicable, but I didn't have the time to look into them now. maybe my solution is somehow equivalent? anyway, it ended up shorter than the zipper-based ones, without any requires https://github.com/euccastro/advent-of-code-2021/blob/main/day18.clj when I read @U076FM90B's description I thought "yes, that's exactly what I did too!", but somehow the actual code seems quite different. my main trick was "make a sequence of the paths to the leaves, then partition that to get the previous and next path for explodes"

👍 1
Andrew Byala03:12:40

Mine was nothing fancy; I just used a whole lot of get-in and similar basic vector functions. Still, it all worked out fairly simply. • https://github.com/abyala/advent-2021-clojure/blob/main/src/advent_2021_clojure/day18.cljhttps://github.com/abyala/advent-2021-clojure/blob/main/docs/day18.md

Antonio Bibiano08:12:29

I went with a flattened list where each number is a pair with value and nesting level

Antonio Bibiano08:12:26

and then used two queues and a buffer to scan the list

Antonio Bibiano08:12:07

took me a lot longer than I anticipated after coming up with the idea 😞

karol13:12:49

https://github.com/kfirmanty/advent-of-code-2021/blob/main/src/day18.clj - this took way longer that I have should probably due to me being sick and not sleeping well 😄 Went with zippers and stick with them but would lie if said I know them well beforehand so had to do a lot of learning while solving it. It is nice that I have purely functional solution that mutates a tree but TBH if I would need to do such task more often I would just use some mutable data structure and be done with it 😄

kingcode05:01:24

I used zippers, fun stuff. Although slow around 18 seconds for part 2 initially, but brought it under 7 secs using pmap

alekszelark13:12:16

It’s almost dead silent today

☝️ 1
karol14:12:28

I am waiting for my kid to go asleep 😄 But took a quick glance at the task in the morning and my gut feeling would to use one inbuilt clojure "library" and the parsing of input looks to be most straightforward of all days (at least in clojure)

🙌 3