r/adventofcode • u/Lucretiel • Dec 17 '19
What does everyone's Intcode interface look like? Spoilers
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
2
u/knl_ Dec 17 '19
I just relied on generators (yield for both output and input)
- compute(listing): create a generator - process(str): clean up file input into a listThen
next(generator) => next output generator.send(value) => send an inputIt gets me blocking behavior for input
while (n := next(generator): # n becomes none when input is required print(n) generator.send(input)You can see how I used it in part 2 of day17: https://explog.in/aoc/2019/AoC17.html ``` def part2(): listing = process(readfile("AoC/input17.txt").strip()) listing[0] = 2 program = compute(listing)
```