Fork me on GitHub

Day 14 - Solutions


This is so sloppy and fast because I want to get to bed so I can go snowboarding tomorrow. Yay!

🏂 2

My solution is coming along. Got the parsing, ASCII visualization and sand falling.. trying to sort out how to detect the termination condition


One could easily cheese it by hard coding based on your specific input.. but a general solution would be nice

Callum Oakley09:12:54

adapted my solution to 2018 day 17, so I don’t know if this is necessarily the most natural algorithm. doesn’t drop a unit of sand at a time, instead keeps track of areas of flowing sand and settled sand. in 2018 the “drop at a time” approach was too slow so I’d be curious to know how long it takes today. this one is ~200ms for part 2 (could certainly speed it up by drawing whole triangles at a time when there are no obstacles!)


Got it! This one was very fun. @U01HL2S0X71 For part 2 my input and algo takes ~4.5 seconds on my computer.

👌 1

@U01HL2S0X71 “Elapsed time: 7734.680185 msecs”

👍 1

did a-step-at-a-time, got 3 seconds for both parts here (on a m1 mac, which is quite fast)


what a cave!

👍 4

@U1EP3BZ3Q looks nice! I also remember seeing some very cool visualizations of the mountain climbing one on reddit

Mark Wardle13:12:19

I didn't use a grid, but just used sets representing the blocks and so looped adding sand along the way and naively faking an infinite floor.


Pretty straightforward but you can always make your life more difficult by writing this:

(apply max (first  (keys world))
to find the maximum x coord in the world instead of this
(apply max (map first  (keys world)


I got up and thought I might feel compelled (shamed?) to do major overhaul, but upon review I think my original approach holds up well, and part 2 only takes about 3s. I got rid of the debug stuff scattered throughout and cleaned up some function signatures and I’m happy with it.


That picture for part 2, @U02P133R2SZ, makes me wonder if it could be solved by subtracting triangles, instead of simulating grains of sand, like what @U01HL2S0X71 was saying. I haven’t done Year 2018 yet, but I seem to recall some puzzle that required adding/subtracting/combining rectangular regions. Hmmm.


@UTFAPNRPT triangles are not a problem I guess, but what about these shapes?


That’s what makes it so interesting. Is there is a way to determine from the vertical and horizontal barriers which triangles (and maybe half triangles) to add and subtract? I’m not saying I’m going to spend the brain power to go figure it out, but it seems like there might be a solution there. (Of course, that is what I thought about normalizing distress signal packets from yesterday, and that turned out to be a fool’s errand. 🙃)

Alexis Schad17:12:11

You could remove the "white" triangle below horizontal lines, but then you have to manage some edge cases where sands can’t reach some areas due to vertical lines.


Nothing special. Exact floor width needed (plus one for aesthetics). I did like this:

(defn simulate-add-sand [cave]
  (let [box (grid/bounds cave)]
    (loop [sand source]
        (grid/ob? box sand)                   :infinite
        (nil? (get cave (m/add sand [0 1])))  (recur (m/add sand [0 1]))
        (nil? (get cave (m/add sand [-1 1]))) (recur (m/add sand [-1 1]))
        (nil? (get cave (m/add sand [1 1])))  (recur (m/add sand [1 1]))
        (= sand source)                       :blocked
        :else                                 (conj cave {sand \o})))))

(defn sim-p2-frames [input]
  (->> (parse-cave input)
       (iterate simulate-add-sand)
       (take-while #(not= :blocked %))))
Lots of optimizations to pursue, but I’d rather work on the Clojure2D viz.


Finally... Used java.util.TreeSet for gathering blocking sand/rock from given column. Clojure2d viz part at the end.

Miķelis Vindavs13:12:35

It’s great. The core idea is very similar to threading (`->>`) in clojure, but with partial application as the default


culi 8 hours ago | next [–]

I just checked the 2nd place[^0] person and they... also have their own programming language...[^1]
What's going on here? Are they just extra motivated to show off their languages? Is making your own programming language more common than I realized?

EDIT: same with the 4th place person[^2]

EDIT2: same with the 7th place[^3]. Btw this is the 4th person that's clickable so actually 3/4 leaders with their GHs linked have their own programming languages

EDIT3: jonahx pointed out I made a mistake and the 2nd place person didn't actually create Vyxal, just used (and contributed) to it






these langs (and code-golf, i.e. going for smallest program byte-size) are mind-blowing! i'd never understood it until this year (i'd always associated the term with vim-golf)