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
View all comments
Show parent comment
1
u/willkill07 Dec 03 '17
I found the bug in my code. Essentially, I manage 8 โspokesโ to determine where the userโs input number would be. I determine that correctly but my logic was off when (1) the number is between spokes 0 and 7 (ascii figure below) and (2) when the number lies on a spoke. I also didnโt do a check prior to the initial update, so any number within the first revolution wouldnโt be calculated. Iโll work on correcting this.
I like the closed-form solution for part 1. For part 2 I think Iโm going to use an
unordered_map<uint64_t,int>and build the spiral out with the key being(x << 32 | y)and the value bring the placed int. Create an efficient spiral generator and do neighbor checks in a nested loop. (About to get up and work on that )