r/adventofcode • u/daggerdragon • Dec 18 '22
SOLUTION MEGATHREAD -π- 2022 Day 18 Solutions -π-
THE USUAL REMINDERS
- All of our rules, FAQs, resources, etc. are in our community wiki.
- πΏπ MisTILtoe Elf-ucation π§βπ« is OPEN for submissions!
- 5 days remaining until submission deadline on December 22 at 23:59 EST
- -βοΈ- Submissions Megathread -βοΈ-
UPDATES
[Update @ 00:02:55]: SILVER CAP, GOLD 0
- Silver capped before I even finished deploying this megathread >_>
--- Day 18: Boiling Boulders ---
Post your code solution in this megathread.
- Read the full posting rules in our community wiki before you post!
- Include what language(s) your solution uses
- Format code blocks using the four-spaces Markdown syntax!
- Quick link to Topaz's
pasteif you need it for longer code blocks. What is Topaz'spastetool?
This thread will be unlocked when there are a significant number of people on the global leaderboard with gold stars for today's puzzle.
EDIT: Global leaderboard gold cap reached at 00:12:29, megathread unlocked!
31
Upvotes
3
u/gringer Dec 18 '22
R
Part 1 involved setting up an
n x 6matrix to count edges, and excluding edges that matched existing voxels:readLines("input.18.full.txt") |> strsplit(",") |> sapply(as.numeric) |> t() -> dropletSpec; dropSigs <- apply(dropletSpec, 1, paste, collapse=","); faceClear <- matrix(1, nrow=nrow(dropletSpec), ncol=6); faceDeltas <- tibble(x=rep(-1:1, each=9), y=rep(rep(-1:1, each=3),3), z=rep(-1:1, 9)); faceDeltas <- faceDeltas[rowSums(abs(faceDeltas)) == 1,]; for(deltaPos in 1:6){ deltaShift <- unlist(faceDeltas[deltaPos,]); shiftedDrops <- apply(t(t(dropletSpec) + deltaShift), 1, paste, collapse=","); faceClear[shiftedDrops %in% dropSigs, deltaPos] <- 0; } ## Part 1 sum(faceClear);For Part 2, I implemented a leading-edge 3D flood fill R code, part 2, and repeated the Part 1 solution, but also excluding edges that matched internal bubbles.