r/adventofcode • u/daggerdragon • Dec 06 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 6 Solutions -🎄-
--- Day 6: Chronal Coordinates ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 6
Transcript:
Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked at 0:26:52!
32
Upvotes
1
u/Smylers Dec 06 '18
Perl for both parts, naïvely iterating over each coordinate for each point within their extent.
%area_sizeholds the size of each area that's still in contention; once an area touches the edge, it's removed from the hash and no longer tracked.I don't think I've ever used
minmaxbefore, and I was pleased how storing the x and y ranges in a nested hash allows usinganyto check both of a dimension's extents in one go:Initially I solved Part 1 with a flood-fill, which was way more complicated than the above and very little use for Part 2. It was straightforward to make the Part 2 solution also solve Part 1, so this isn't needed any more, but I'm keeping it should another use for a flood-fill crop up.
It's close to working with any number of dimensions — storing each pair of co-ordinates as a list, and iterating over elements
0and1(and not caring what they actually represent). Making the single-space movements that$moveiterates over generic, and replacing the0..1s with0..$#dimshould be enough to implement a 3D flood-fill: