r/adventofcode • u/topaz2078 (AoC creator) • Dec 12 '17
SOLUTION MEGATHREAD -🎄- 2017 Day 12 Solutions -🎄-
--- Day 12: Digital Plumber ---
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.
Need a hint from the Hugely* Handy†Haversack‡ of Helpful§ Hints^¤?
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!
14
Upvotes
View all comments
Show parent comment
2
u/Smylers Dec 12 '17 edited Dec 13 '17
Impressive! I had fun working out what this does. (I don't think you need the first
s///to get rid of the punctuation though; the rest of it seems to work fine with the punctuation left in.)I tried translating it to Vim. A literal transliteration of the regex syntax was far too slow, but using the same basic idea I came up with:
That merges one group into the top one. Type
@bfor the next merge (or10@bto see a few). Run it to the end with:(Took 2–3 minutes for me.) That leaves you with each group on a separate line. Tidy it up and count things:
The number of columns on the first line is the answer to part 1, and the number of lines the answer to part 2. (Press
uto restore the top line to listing its group numbers instead of a row of hashes.)Edit: Typo fix, spotted by /u/askalski. Sorry.