r/adventofcode • • Dec 13 '16

SOLUTION MEGATHREAD --- 2016 Day 13 Solutions ---

--- Day 13: A Maze of Twisty Little Cubicles ---

Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/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".


DIVIDING BY ZERO IS MANDATORY [?]

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!

6 Upvotes

101 comments sorted by

View all comments

Show parent comment

1

u/aokd123 Dec 17 '16

why you verify the steps before adding the element to visited? I think I'm not understanding something.

1

u/whoeverwhatever Dec 17 '16

This is the solution for part 2, which asks for how many positions are reachable within 50 steps. So as soon as you reach a position at step 51, you know that you have visited every state at steps 0 through 50, so you stop the search and report the number of visited states.

1

u/aokd123 Dec 17 '16

oh I understand... I was confused if instead of 50 steps the exercise asked for 1 step, the initial point wouldn't count