Trying to finish up 2019
This commit is contained in:
1
2019/day23/input
Normal file
1
2019/day23/input
Normal file
File diff suppressed because one or more lines are too long
70
2019/day23/main.go
Normal file
70
2019/day23/main.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
intcode "git.bullercodeworks.com/brian/adventofcode/2019/intcode-processor"
|
||||
//helpers "git.bullercodeworks.com/brian/adventofcode/helpers"
|
||||
)
|
||||
|
||||
func main() {
|
||||
//pt := helpers.GetArgNumber(1)
|
||||
prog := intcode.ReadIntCodeFile("input")
|
||||
//if pt == "1" {
|
||||
part1(prog)
|
||||
//} else {
|
||||
// part2(prog)
|
||||
//}
|
||||
}
|
||||
|
||||
func part1(prog []int) {
|
||||
var network []*intcode.Program
|
||||
msgQueue := make([][]int, 255)
|
||||
for k := 0; k < 50; k++ {
|
||||
p := intcode.NewProgram(prog)
|
||||
//p.EnableDebug()
|
||||
network = append(network, p)
|
||||
msgQueue = append(msgQueue, []int{})
|
||||
go func(addr int) {
|
||||
for !network[addr].NeedsInput() {
|
||||
time.Sleep(1)
|
||||
}
|
||||
network[addr].Input(0)
|
||||
for {
|
||||
if !network[addr].NeedsOutput() && !network[addr].NeedsInput() {
|
||||
time.Sleep(1)
|
||||
} else if network[addr].NeedsOutput() {
|
||||
msgD := network[addr].Output()
|
||||
msgQueue[msgD] = append(msgQueue[msgD], network[addr].Output())
|
||||
msgQueue[msgD] = append(msgQueue[msgD], network[addr].Output())
|
||||
fmt.Println(addr, "->", msgD, msgQueue[msgD])
|
||||
} else if network[addr].NeedsInput() {
|
||||
if len(msgQueue[addr]) > 0 {
|
||||
var v int
|
||||
v, msgQueue[addr] = msgQueue[addr][0], msgQueue[addr][1:]
|
||||
fmt.Println(addr, "<-", v)
|
||||
network[addr].Input(v)
|
||||
} else {
|
||||
network[addr].Input(-1)
|
||||
}
|
||||
}
|
||||
}
|
||||
}(k)
|
||||
go network[k].Run()
|
||||
}
|
||||
for len(msgQueue[255]) < 2 {
|
||||
time.Sleep(1)
|
||||
}
|
||||
fmt.Println(msgQueue[255])
|
||||
}
|
||||
|
||||
func part2(prog []int) {
|
||||
}
|
||||
|
||||
func getOutput(p *intcode.Program) int {
|
||||
for !p.NeedsOutput() {
|
||||
time.Sleep(1)
|
||||
}
|
||||
return p.Output()
|
||||
}
|
Reference in New Issue
Block a user