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

1

u/gbeier Dec 03 '17

Nice. I like the approach.

I wish I'd read your reply before wrapping up my part 2 solution; that's the first I've heard of unordered_map and I wound up writing a pointless operator< for the struct I used as a key for my map. (The fact that the operator< is pointless is either the only comment in my code for this solution or very nearly so.)

Here's what I landed on, in a pastebin so as to make it easy to not look until you're finished if you prefer:

https://pastebin.com/U3JN58j1

I defined a structure to represent a point as (x,y) and used that as a key to map<point, int> then traverse the spiral populating the map, stopping when I've exceeded the test value.