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!

20 Upvotes

297 comments sorted by

View all comments

Show parent comment

2

u/edelans Dec 05 '17

okI think I get it :

  • s is the length of the side of each "square" of the spiral
  • (ds, di, dj) in [(0,1,0),(0,0,-1),(1,-1,0),(1,0,1)]: are all the different directions the spiral takes on one square (notice that your spiral turns clockwise whereas the one of the exercise turns the other way... but that obviously does not change the result)
  • for _ in range(s+ds) are all the movements on one direction

this is SO neat.

2

u/oantolin Dec 06 '17

Yes, that's right. (I wrote another explanation before I saw this comment, you can ignore it.)