adventofcode

Aleks 2021-12-22T04:48:03.262900Z

🧵 Day 22 Solutions Thread: post your solution here

kevinc 2021-12-24T19:37:55.293Z

https://github.com/kconner/advent-of-code/blob/master/2021/22a.clj, https://github.com/kconner/advent-of-code/blob/master/2021/22b.clj. In both cases I worked one dimension at a time. And if you process the steps in reverse order, then you only need to think about the space that no prior step has mentioned yet. In graphics terms, this is like the way a Z-buffer can prevent overdraw, but only when you draw front-to-back. For part 1 I iterated over all x, y, and z values, filtered steps' boxes by whether they intersected that plane, and counted the value from the first match over all three dimensions. For part 2 I inserted each box in a tree where the root node holds a list of mutually exclusive intervals across x, with child nodes doing the same for the next dimension (unless that interval is empty). Inserting a box involves splitting intervals over new planes, then recursing to insert into the existing child node on the next dimension. There are plenty of ways to improve performance but 4.5s was ok for me. I shudder to think of copying those child nodes without persistent collections!

Aleks 2021-12-22T09:02:40.265900Z

Refactored my solution

Callum Oakley 2021-12-22T13:30:07.267Z

keeps track of the sequence of disjoint cuboids that are on, so that the result is the sum of the volumes. bit of a mess and pretty slow. will probably revisit to try and clean it up later. 49s https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/22.clj

Callum Oakley 2021-12-22T13:32:00.267200Z

I see you’re both doing something totally different! very neat. how long does it take? looks like it’s probably faster…?

Aleks 2021-12-22T16:00:12.267700Z

it’s pretty fast

Aleks 2021-12-22T16:01:06.267900Z

~156msecs

šŸ‘Œ 1
Aleks 2021-12-22T16:06:02.268100Z

@tonsky used a different approach, ~829msecs on my machine https://github.com/tonsky/advent-of-code/blob/main/src/advent_of_code/year2021/day22.clj

Antonio Bibiano 2021-12-22T17:15:33.268500Z

Took me a while! after solving it completely wrong the first time..

šŸ‘Œ 1
Antonio Bibiano 2021-12-22T17:19:06.268900Z

I keep track of the sizes of the input cuboids and the cuboids that result from an overlap with negative size

Antonio Bibiano 2021-12-22T18:48:13.269600Z

Takes 12 seconds though šŸ˜ž i end up with 32191 cuboids in my list..

Callum Oakley 2021-12-22T19:02:22.270Z

re-wrote my solution based on the same method as @zelark and @norman. thanks both šŸ™ 23ms/36ms now https://github.com/callum-oakley/advent-of-code/blob/main/src/aoc/2021/22.clj fun function of the day, inspired by haskell’s tails (probably should be a lazy-seq for serious use)

(defn rests [coll]
  (when (seq coll)
    (cons coll (rests (rest coll)))))

šŸ‘šŸ» 1
Antonio Bibiano 2021-12-22T20:35:02.270400Z

the visualization for today are so cool

Callum Oakley 2021-12-22T21:52:11.270700Z

agreed! I chuckled at this:

2021-12-22T05:03:07.263900Z

Any time I see 3d-space questions, I dread getting started

lread 2021-12-23T23:37:55.279700Z

Yeah https://github.com/quil/quil seems to be helping me with the 3d puzzles. Had to wrap my brain around how it works, but I understand the basics enough to play a bit!

lread 2021-12-22T22:46:34.271400Z

Same. I need to visualize my experiments. And that’s hard for me to do in my brain when reading textual x y x coords. Maybe adding a graphics library to draw the 3d things would help. Know of any that might work well?

lread 2021-12-23T01:07:49.271700Z

I’m starting to play with quil… haven’t got far yet…

Aleks 2021-12-22T09:28:15.266300Z

https://twitter.com/algrison/status/1473344262762905612?s=20 made by @a.grison, not me