This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-22
Channels
- # adventofcode (21)
- # announcements (2)
- # babashka (35)
- # beginners (45)
- # calva (22)
- # cider (28)
- # clj-kondo (39)
- # clj-on-windows (69)
- # clojure (28)
- # clojure-europe (15)
- # clojure-nl (7)
- # clojure-uk (24)
- # clojurescript (95)
- # cursive (9)
- # data-science (3)
- # datalevin (2)
- # emacs (11)
- # etaoin (9)
- # fulcro (1)
- # graphql (4)
- # jobs (8)
- # lsp (66)
- # malli (10)
- # missionary (3)
- # pathom (4)
- # polylith (67)
- # releases (3)
- # reveal (2)
- # shadow-cljs (53)
- # spacemacs (2)
- # specter (1)
- # sql (1)
- # tools-deps (6)
- # vim (4)
- # xtdb (16)
🧵 Day 22 Solutions Thread: post your solution here
Refactored my solution
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
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
@U050UBKAA used a different approach, ~829msecs on my machine https://github.com/tonsky/advent-of-code/blob/main/src/advent_of_code/year2021/day22.clj
I keep track of the sizes of the input cuboids and the cuboids that result from an overlap with negative size
Takes 12 seconds though 😞 i end up with 32191 cuboids in my list..
re-wrote my solution based on the same method as @U067R559Q and @U0954HGDQ. 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)))))
the visualization for today are so cool
agreed! I chuckled at this:
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!
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?
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!