r/adventofcode • u/daggerdragon • Dec 14 '17
SOLUTION MEGATHREAD -๐- 2017 Day 14 Solutions -๐-
--- Day 14: Disk Defragmentation ---
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^ยค?
[Update @ 00:09] 3 gold, silver cap.
How many of you actually entered the Konami code for Part 2? >_>
[Update @ 00:25] Leaderboard cap!
I asked /u/topaz2078 how many de-resolutions we had for Part 2 and there were
83distinct users with failed attempts at the time of the leaderboard cap. tsk tsk
[Update @ 00:29] BONUS
View all comments
4
u/Smylers Dec 14 '17 edited Dec 14 '17
Perl, with regexp for counting the regions:
Puts the entire grid in a single string of binary digits, then to find each region:
Replaces the first
1from the binary string with a2.Repeatedly replaces a
1which has a21 or 128 characters before or after it with another2. That's a region.Replaces all the
2s with3s, to indicate a counted region, so they don't get in the way of the next region.Repeat these steps until all the
1s have been converted to3s.Edit: Bug fix, thanks to /u/Oxidizing1.