2019 Day 5 Complete
* Also: Move helpers to their own submodule, for importing
This commit is contained in:
38
2019/day05/main.go
Normal file
38
2019/day05/main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user