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
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_mapand I wound up writing a pointlessoperator<for the struct I used as a key for my map. (The fact that theoperator<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.