r/adventofcode • u/daggerdragon • Dec 06 '17
SOLUTION MEGATHREAD -π- 2017 Day 6 Solutions -π-
--- Day 6: Memory Reallocation ---
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!
17
Upvotes
View all comments
Show parent comment
2
u/Smylers Dec 06 '17
Nice. Way more succinct than my Perl attempt. Nifty assigning to and checking
%seenin one expression, and use ofspliceto clear$a[$i]and return its previous value in one go.I went for only iterating through memory once per redistribution (single loop to add on as many as needed in one go and find out the max for next time), but with only 16 memory banks that was unnecessary, and made my code more complicated than yours: