Fork me on GitHub
<
2022-12-18
>
norman06:12:36

Day 18 - Solutions

norman06:12:30

https://gitlab.com/maximoburrito/advent2022/-/blob/main/src/day18/main.clj 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...

rjray06:12:11

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.

rjray06:12:02

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 😄

rjray07:12:51

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

misha12:12:33

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

alekszelark13:12:58

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)
(vals)
(filter #(== (count %) 1))
(count))``````

Miķelis Vindavs13:12:54

group-by + count can be replaced with frequencies

1
alekszelark13:12:52

nice catch

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

alekszelark13:12:24

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

Alex Alemi14:12:05

Today was a welcome reprieve from the last couple days: https://github.com/alexalemi/advent/blob/main/2022/clojure/p18.clj

Felipe19:12:27

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

bhauman18:12:45

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

bhauman18:12:20

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

bhauman19:12:26

found it 😞

wevrem01:12:05

I’m slowly catching up. Wrote a very concise `flood` function. https://github.com/wevre/advent-of-code/blob/master/src/advent_of_code/2022/day_18_droplets.clj

2
nbardiuk16:12:43

Today has started another advent style puzzles challenge https://hanukkah.bluebird.sh/ . First day looks fun, on the level of first week of advent of code

👀 1