Fork me on GitHub

Day 18 - Solutions

norman06:12:30 I'm actually quite happy with this code for a change. Thankfully the technique suggested by the problem statement turned out to be a good direction...


I got part 1 easily-enough, but I'm getting one more air-pocket than I should when running part-2 on the example data.


It's weird-- I checked it out and the "wrong" air-pocket is in fact surrounded by blocks on all 6 faces.

Miķelis Vindavs07:12:15

@U0954HGDQ i like the brutal way to get the (cubic) bounds 😄


Hmmm... from reading reddit, looks like I should be doing a BFS or flood-fill. Think I'll try the BFS first.

Miķelis Vindavs07:12:50

on my input it didn’t matter, but i tried expanding the area by a lot and DFS was much much faster. It makes sense — if you want to check if you can reach the edge, try going far in one direction first vs circling around the origin


btw, bubbling might be way faster than flood: most of voxels are surface, and the rest would need a several-steps-long search


Probably not an ordinary solution for part 1. It was my first attempt before I realized BFS saves the day

(defn surfaces [[x y z :as coords]]
  (map #(-> #{%1 (mapv + %1 %2)})
       (concat (repeat 3 coords)
               (repeat 3 [(inc x) (inc y) (inc z)]))
       [[ 1  1  0] [ 1  0  1] [ 0  1  1]
        [-1 -1  0] [-1  0 -1] [ 0 -1 -1]]))

(->> (parse large-example)
     (mapcat surfaces)
     (group-by identity)
     (filter #(== (count %) 1))

Miķelis Vindavs13:12:54

group-by + count can be replaced with frequencies


nice catch

(->> (parse large-example)
     (mapcat surfaces)
     (filter #(== (second %) 1))


“Unfortunately, you forgot your flint and steel in another dimension.” 🧊

Alex Alemi14:12:05

Today was a welcome reprieve from the last couple days:


immediately not proud anymore after seeing your solutions in half the line count


Well my flood fill seems to work so I’m curious what I’m missing for the second part.


I’m also counting surfaces that are “out of bounds”


found it 😞


Today has started another advent style puzzles challenge . First day looks fun, on the level of first week of advent of code

👀 1