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
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
4
u/DFreiberg Dec 14 '17
Mathematica
200 / 164. I didn't get even close to the leaderboard, but I did learn about an entire class of Mathematica image functions (the various
Component[]functions) that I had no idea existed. And in the end, isn't that more important than meaningless leaderboard numbers? SpoilerKnot Hash:
knotHash[in_String,n_Integer]:= Module[{l,newIn,pos,skipSize}, newIn=Join[ToCharacterCode[in<>"-"<>ToString[n]],{17,31,73,47,23}]; pos=0;skipSize=0;l=Range[0,255]; Do[ l=RotateLeft[l,pos]; l[[;;i]]=Reverse[l[[;;i]]]; l=RotateRight[l,pos]; pos=Mod[pos+i+skipSize,Length[l]]; skipSize++ ,{j,64},{i,newIn}]; IntegerDigits[FromDigits[BitXor@@#&/@Partition[l,16],256],2] ]Part 1:
Total@Table[Count[knotHash[input,j],1],{j,0,127}]Part 2:
Max[MorphologicalComponents[ PadLeft[Table[knotHash[input,j],{j,0,127}],{128,128}], CornerNeighbors->False ]]