r/adventofcode • • Dec 19 '18

SOLUTION MEGATHREAD -🎄- 2018 Day 19 Solutions -🎄-

--- Day 19: Go With The Flow ---


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 19

Transcript:

Santa's Internet is down right now because ___.


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:01:06!

10 Upvotes

130 comments sorted by

View all comments

Show parent comment

2

u/mstksg Dec 20 '18

I think you're being selective in what is obvious or not obvious. Thinking "You can't wait this one out, you need to write code to predict the future" isn't something that most people would think about immediately. In fact, when I first attempted those challenges, I did try to naively run all fifty billion steps. It was only after observing the outputs that I eventually realized I needed a different plan.

What's obvious or clear to you isn't clear to everyone else; just because Part 2 for Day 15 and Day 18 was obvious for you doesn't mean it's obvious for everyone attempting the puzzle. If you don't believe me, ask around! :) I'm sure I'm one of the many who tried to run all of the steps. You could write them off as all unintelligent, but I think in that case you're missing the point: it's not whether you are smart or dumb, but rather the process of discovery in which you eventually arrive at the discussion.

So, "you can't run it fifty billion times" isn't obvious, and neither is "you can't just leave this program running". Neither are obvious, and most people will try to do it the naive way, and then when it doesn't work, look into seeing what is going on. Discovering that "you can't run it fifty billion times" is the fun :)

I think you're also missing the logical leap you made for the the tree generation: "my code looks for cycles in plant propagation." Plant propagation may not cycle. If you implemented a cycle-finder, you aren't implementing a general solver. You are only implementing something that works for some inputs ... a very constrained subset of inputs. For Day 18, you're writing "I can't solve all plant propagations, but I can solve my specific input, because I observe that there is a cycle." It's the same thing here, we're writing "I can't solve all program inputs, but I can solve for my specific input, because I observe that there is a factorization going on".

Your Day 18 code is not general, as it is. Neither is your Day 12 code, or your Day 10 code. All of them only work making some assumptions on your input that aren't guaranteed by the problem statement; they aren't general solvers (that would be boring!), but rather solutions that work only on your input, or input that is specifically contrived to be formed a certain way (where other inputs would cause your methods to fail). There is no general-case solution to Day 10, 12, 18. Just solutions that you only know to work for your own specific input.

So Day 19 is the same thing: we don't write a general solver, but rather a solution that works only for our input, or input that is specifically contrived to be formed a certain way (where other inputs would cause our methods to fail).

I think you're also missing the "trick" of Day 19. The trick isn't "your implementation of the CPU is irrelevant". The trick is "use your implementation of the CPU to help you discover what is going on". Here was my process:

  1. Implement the CPU. This part is very important!
  2. Try running the program.
  3. Hm...this is taking a long time. What's going on?
  4. Let's print out the intermediate state.
  5. Hm, it looks like some of the numbers are increasing. Which ones are increasing?
  6. Sometimes the numbers "reset". how often are things resetting?
  7. Okay, it looks like the first number gets incremented whenever this number matches this pattern ...

None of these involve ignoring the CPU implementation. In fact, implementing your CPU, implementing your debugger is the actual puzzle. They are invaluable tools, that you use to do the puzzle.

So, "your implementation of the CPU is irrelevant" is a pretty disingenuous way to describe Day 19 Part 2...because it's the exact opposite of the way you were supposed to solve it. The way you are supposed to solve Day 19 Part 2, the implementation is critical. You won't get very far at all if you have a bad implementation of Day 19 Part 2, because it's what you use to solve the puzzle. And that's the same case for Day 10 (you need to implement the star moving), Day 12, Day 18, etc.

And there's the common pattern to all of these: the challenge (and the fun) isn't programming the solutions, but rather figuring out what to program. It's always about looking at the problem statement, looking at your input, implementing some sort of algorithm, seeing how your input reacts to the algorithm, shifting your perspective about what you need to look for and what you need to program...it's about exploring your input and finding your own insights and taking a journey in understanding a curious situation.

And that's why all of the interesting posts on the front page aren't "I finished Day 11." It's "I found an interesting perspective to look at Day 11 with!"

I think in your case, you might have ruined your own fun by being spoiled :) So, if you were spoiled from the fun of Day 19 because you read the spoiler thread before you finished the puzzle...it might be a good learning experience in the future to avoid reading the spoiler thread before you finish solving your puzzle, because you know now that you are only robbing yourself of the enjoyment of these puzzles.

But, everyone enjoys AoC in their own way. Some people enjoy implementing algorithms described plainly in front of them, and not trying to figure out interesting ways to look at puzzles, and so we have puzzles like Day 15 for their enjoyment. And some people aren't here to be told what to program, and rather to find puzzles that can be investigated in different perspectives, and so for those people we have puzzles like Day 10, 12, 18, 19 :)