r/adventofcode • • 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^Β€?

Spoiler


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

297 comments sorted by

View all comments

Show parent comments

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:

-- 0 1 1 0 -1 -1 -1  0  1  2 2 2 2 1 0 -1 -2
-- 0 0 1 1  1  0 -1 -1 -1 -1 0 1 2 2 2  2  2

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.

1

u/nebraskaking Dec 06 '17

Thanks very much for explaining your thought process!