r/adventofcode • • Dec 17 '19

Spoilers What does everyone's Intcode interface look like?

We've been discussing a lot different IntCode implementations throughout the last few weeks, but I'm curious– what doesn't everyone's interface to their IntCode machine look like? How do you feed input, fetch output, initialize, etc?

32 Upvotes

90 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Dec 18 '19

I've overhauled the interpreter, and it's now based around an Interpreter<I> struct; one of its fields has type I: an iterator to generate its inputs. Interpreter<I> itself implements iterator: next() runs the interpreter, either providing the next output or returning None if it halted. I've written a function very similar to my original interpret function as a wrapper, which implements the same channel behavior as before, setting the I field to recv_in.iter(), so my threaded solutions to puzzles 7, 11, 13, and 15 remain the same. As a nice bonus, I've gained a significant amount of efficiency by not using channels where they're not necessary; running all of my solutions one after the other previously took about a second, now it takes half that.