package main

import (
	"fmt"
	"strings"

	"github.com/bewuethr/advent-of-code/go/convert"
	"github.com/bewuethr/advent-of-code/go/intcode"
	"github.com/bewuethr/advent-of-code/go/ioutil"
	"github.com/bewuethr/advent-of-code/go/log"
)

func main() {
	scanner, err := ioutil.GetInputScanner()
	if err != nil {
		log.Die("getting scanner", err)
	}

	scanner.Scan()
	opCodesStr := strings.Split(scanner.Text(), ",")
	if err := scanner.Err(); err != nil {
		log.Die("reading input", err)
	}

	opCodes, err := convert.StrSliceToInt(opCodesStr)
	if err != nil {
		log.Die("converting string slice to int", err)
	}

	comp := intcode.NewComputer(opCodes)
	comp.RunProgram()
	comp.Input <- 1
Loop:
	for {
		select {
		case err := <-comp.Err:
			log.Die("running op codes", err)
		case <-comp.Done:
			break Loop
		case output := <-comp.Output:
			fmt.Println(output)
		}
	}
}

package main

import (
	"strings"

	"github.com/bewuethr/advent-of-code/go/convert"
	"github.com/bewuethr/advent-of-code/go/intcode"
	"github.com/bewuethr/advent-of-code/go/ioutil"
	"github.com/bewuethr/advent-of-code/go/log"
)

func main() {
	scanner, err := ioutil.GetInputScanner()
	if err != nil {
		log.Die("getting scanner", err)
	}

	scanner.Scan()
	opCodesStr := strings.Split(scanner.Text(), ",")
	if err := scanner.Err(); err != nil {
		log.Die("reading input", err)
	}

	opCodes, err := convert.StrSliceToInt(opCodesStr)
	if err != nil {
		log.Die("converting string slice to int", err)
	}

	comp := intcode.NewComputer(opCodes)
	if err := comp.RunProgram(1); err != nil {
		log.Die("running op codes", err)
	}
}

--- 
+++ 
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"fmt"
 	"strings"
 
 	"github.com/bewuethr/advent-of-code/go/convert"
@@ -27,7 +28,17 @@
 	}
 
 	comp := intcode.NewComputer(opCodes)
-	if err := comp.RunProgram(1); err != nil {
-		log.Die("running op codes", err)
+	comp.RunProgram()
+	comp.Input <- 1
+Loop:
+	for {
+		select {
+		case err := <-comp.Err:
+			log.Die("running op codes", err)
+		case <-comp.Done:
+			break Loop
+		case output := <-comp.Output:
+			fmt.Println(output)
+		}
 	}
 }
Update 2019 day 5, first part, for new intcode computer
