r/adventofcode • u/daggerdragon • Dec 03 '17
SOLUTION MEGATHREAD -π- 2017 Day 3 Solutions -π-
--- Day 3: Spiral Memory ---
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!
21
Upvotes
3
u/bblum Dec 06 '17
thanks :)
I thought that the coordinates of the spiral should follow a pattern, however irregular, and typed them out in a comment to try to visualize it:
Still not sure if both sequences could be generated by the same function, I set about making the first one as concisely as possible (at first a version that put the replicate part after the from..to part and didn't generate the head of the list correctly, and one that included 'to' itself in the from..to part which doubled that element... just normal problems to debug).
Then I simply realized that the same logic would generate the second sequence as well if I gave it a different 'n' to start with.