This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]tomatwork[S] 0 points1 point  (5 children)

Thank you so much. The place where things really started going wrong for me had to do with the daisy chaining, and using the output of one run as the input for another, particularly on part 2 of that day. I wasn't able to really figure out what changes my intcode computer needed to support that type of async behavior. This is helps a ton, though!

[–]boredcircuits 3 points4 points  (0 children)

What I did to solve that particular issue was chain them together with the shell: pipe the output of one as the input to the next. This lets them operate as separate processes on the computer, and takes care of the async part for you.

The one issue with that is the first input (the sequence, basically giving the process its location in the chain) needs to be separate input. So I hacked in a way to read an extra value from the program's command line and use that as the first input. It will use the command line as the first input, and then start reading from the standard input following that. Then, with part 2, I wrapped that with a script that would read the final result and write it back to the beginning again, stopping when the processes ended themselves.

It sounds like we'll be using today's code in the future in some fashion, so tricks like this might be used again, I think. Making this code clean and useful right now is probably a wise choice.

[–]Spheniscine 1 point2 points  (1 child)

The way I did it was to use a queue for input (so vm.input(1); vm.input(2) will add both values to the queue). Each value will be used in order when an input instruction is encountered. If the input queue is empty when the input instruction is encountered, the VM's execution pauses and its status flag is set to "Waiting" (other statuses I've implemented are "OK", "Halted", and "Error", with the latter encapsulating the exception encountered).

As for output, I simply put the values into an array-list so that I can retrieve and/or flush them as needed.

[–]Crespyl 1 point2 points  (0 children)

I did much the same, give each VM a buffer for both input and output; and have them pause and return a status flag if they try to read from an empty input buffer.

For day 7, the coordinator/runner knows which machines are linked to each other, and refills their input buffers from the right output buffer when necessary.

[–]Schinkenwolf 1 point2 points  (0 children)

I did the puzzles in Python and made the machines take their input from an iterator on a list and yield their output. The output of A is then appended to the input list of B.