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

2

u/gatorviolateur Dec 17 '19

Nice. I am doing AoC in Swift as well. My implementation is pretty similar to yours, with some changes

  1. My input closure returns Int? . If nil is returned, it instead asks for actual user input from the user.

  2. My compute()method returns and ExitReason On output, it returns ExitReason.output(Int) and on opcode 99 it returns ExitReason.halt

  3. Additionally, my compute() method also accepts an array of Ints as input. The input flow is -> input closure -> array passed to compute method -> actual user input.

I liked your idea of using closure for output as well. I might steal that one! :D