Fork me on GitHub

🧵 Day 22 Solutions Thread: post your solution here


Refactored my solution

Callum Oakley13:12:07

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

Callum Oakley13:12:00

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


it’s pretty fast



👌 1
Antonio Bibiano17:12:33

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

👌 1
Antonio Bibiano17:12:06

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

Antonio Bibiano18:12:13

Takes 12 seconds though 😞 i end up with 32191 cuboids in my list..

Callum Oakley19:12:22

re-wrote my solution based on the same method as @U067R559Q and @U0954HGDQ. thanks both 🙏 23ms/36ms now 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)))))

Antonio Bibiano20:12:02

the visualization for today are so cool

Callum Oakley21:12:11

agreed! I chuckled at this:

kevinc19:12:55, 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!


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


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?


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


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