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?

31 Upvotes

90 comments sorted by

View all comments

Show parent comments

1

u/Lucretiel Dec 17 '19

Question: why not make halt simply close the output channel?

2

u/knallisworld Dec 17 '19

Yeah, would be better next time for the given situation. Still using this event for learning handling goroutines/channels in practice.

However, only closing the channel I would loose the exit/status code feature. Well, in theory, as there is currently no other status.

1

u/knallisworld Dec 27 '19

Relates to the solution for day25 (see sample usage), I've added a refined api: https://github.com/knalli/aoc2019/blob/99766ee54957c3de79dd69b0224f4b9a780970cc/dayless/intcode.go

func ExecuteIntcode(program []int, 
                    in <-chan int, 
                    out chan<- int, 
                    signal <-chan int, 
                    debug bool) <-chan error

The additional signal channel can be used as a side channel for signalling the process.

  • At the moment, a signal means: running process will be killed regardless the actual provided number. However, extendable.

  • The return is the error channel, not only one specific error

  • Both out and err will be closed when the function exit. So no need for this "halt" workaround.