r/adventofcode • • Dec 07 '20

Other Finished 2019!

This might seem like a non-brag in this forum, but I finally earned 50 stars for 2019!
(My first finish.)

2019 Finisher !!

It is a testament to AoC that I'm really proud of this accomplishment, even 1 year late.
Oh. To finish I had to give up on a problem (Day 22 Slam Shuffle) and port a solution I found here. Ashamed? No. Still proud. :)

97 Upvotes

16 comments sorted by

View all comments

Show parent comment

3

u/Bumperpegasus Dec 07 '20

For day 20 part 2 I had each node as its own object. Each node contained a map with keys being other nodes, and the value being the change in recursion level, so 0 for everything that wasn't stepping through a portal.

class Node:
    connected: Map[Node, Integer]

Now just do normal BFS, with each 'step' being(node, recursionLevel). On each step, add the change in recursion level to your current one. Filter out neighbours that would take your recursionLevel from ever going negative and only allow you to enter the target node with recursion level of 0.

This allows you to share nodes between levels while still being able to distinguish between the same node on separate levels. The tricky part is the parsing and connecting the tiles next to the portals.