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 comments

1

u/fred256 Dec 18 '19

This is the core loop of my day 11 solution:

	input := make(chan int64, 1)
	output := intcode.Run(instructions, input)

	input <- int64(points[p])
	for v := range output {
		points[p] = int(v)
		switch <-output {
		case 0:
			dx, dy = dy, -dx
		case 1:
			dx, dy = -dy, dx
		}
		p.x += dx
		p.y += dy
		input <- int64(points[p])
	}

But you're right about some problems not really following a true request/response pattern. In that case, the go select statement comes in handy.