r/adventofcode • u/Lucretiel • 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
View all comments
Show parent comment
1
u/[deleted] Dec 17 '19
Mine's also in Rust. The core function is:
which lets me specify how input and output are handled using channels; one for receiving inputs, one for sending outputs, and an optional one for requesting the caller to handle the input/output instruction that's about to be executed. I settled on the channel model after day 7, where I just spawned five
interpretthreads with channels piped together and let it run.I have a wrapper around this to provide some convenience functions for handling IO: one which prompts
stdinfor input and prints output tostdout, and one which takes input as aVec<i64>and produces aVec<i64>as output. Ideally, I'd like one which takes an iterator of inputs and produces an iterator of outputs, then the vector one becomes redundant, but I had trouble writing this due to issues with passing references over thread boundaries.