adventofcode/2019/day05/main.go

39 lines
634 B
Go

package main
import (
"fmt"
"os"
"strings"
"time"
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
)
func main() {
inp := helpers.StdinToString()
var prog []int
for _, v := range strings.Split(inp, ",") {
prog = append(prog, helpers.Atoi(v))
}
p := intcode.NewProgram(prog)
go p.Run()
// Part 1:
// p.Input() <- 1
// Part 2:
p.Input() <- 5
go func() {
for {
out := <-p.Output()
fmt.Println(out)
if p.State() != intcode.RET_OK {
os.Exit(0)
}
time.Sleep(50)
}
}()
for {
time.Sleep(time.Second)
}
}