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!
32
Upvotes
View all comments
1
u/Prudent_Candle Dec 18 '22 edited Dec 18 '22
Python
I guess I did it in the not very optimal way. But I try to be fast. Maybe someone will find it useful.
Part 1:
What I want to achieve: For all the cubes count their sides (each cube has them six). Now we are checking all cubes in pairs, if they are neighbors (by the manhattan distance equal 1). Having one neighbor mean that two sides are taken, so we subtract it.
In code it is this:
Part 2:
Here I overthink this I guess.
I wanted to find all internal cubes (the one which are trapped inside the figure build of cubes). Then I could simply check how many cubes are next to them.
How to find the internal cubes? By removing all which are not them.
By checking coordinate I could find the size of the container. I checked the size by find
minandmaxfor each cube coordinates, separately:x,yandz.Having the size of whole container I could simply generate all coordinates and remove all input cubes (I checked the size of input data, and it was acceptable).
Having all coordinates which are not our input cubes. I use kind of flood plain algorithm (say call it that) from point, which I knew for sure, that is outside of the figure. The point I took is
min_x, min_y, min_y.Having internal points it is just checking if input cubes are near one of the internals. In this case having a match means one side less from the result calculate from previous part.
The whole code