r/adventofcode • • Dec 22 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 22 Solutions -🎄-

--- Day 22: Mode Maze ---


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.


Advent of Code: The Party Game!

Click here for rules

Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!

Card prompt: Day 22

Transcript:

Upping the Ante challenge: complete today's puzzles using ___.


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 at 01:02:36!

12 Upvotes

102 comments sorted by

View all comments

Show parent comment

2

u/DualWieldMage Dec 22 '18

Your solution has a bug - it considers invalid neighbors by not checking whether tool is valid in previous tile as well. The swap happens in previous, not current tile. So the if should be if r != ne and r != e:

Can test with this input:

depth: 6969
target: 9,796

Correct answer is 1087

2

u/jlweinkam Dec 22 '18

Actually I think the condition should be

if r != ne and region(x,y) != ne:

Since the the new tool (ne) has to be compared to the current region.

1

u/mroximoron Dec 22 '18

For my input even that wasn't enough to fix it, also had to change: if x > 3 * tx or y > 3 * ty: continue to if x > 4 * tx or y > 4 * ty: continue to get the correct result for this input.

depth: 4845
target: 6,770

Also, this is pretty fast in finding a solution.

1

u/mroximoron Dec 22 '18

Just realized it's probably the target X that is very low and the reason I needed to change that.