Trying to finish up 2019

This commit is contained in:
2020-11-03 05:02:36 -06:00
parent ac0772f966
commit 4f1712ceb0
13 changed files with 1044 additions and 44 deletions

1
2019/day21/input Normal file

File diff suppressed because one or more lines are too long

83
2019/day21/main.go Normal file
View File

@@ -0,0 +1,83 @@
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) {
p := intcode.NewProgram(prog)
//p.EnableDebug()
var lastOut int
go func() {
for {
if !p.NeedsOutput() && !p.NeedsInput() {
time.Sleep(1)
} else if p.NeedsOutput() {
lastOut = getOutput(p)
fmt.Print(string(byte(lastOut)))
} else if p.NeedsInput() {
instructions := "NOT A J\nNOT C T\nOR T J\nAND D J\nWALK\n"
//instructions := "NOT A J\nWALK\n"
for _, v := range []byte(instructions) {
fmt.Print(string(v))
p.Input(int(v))
}
}
}
/*
fmt.Println(getOutput(p))
return
*/
}()
p.Run()
fmt.Println("Damage:", lastOut)
}
func part2(prog []int) {
p := intcode.NewProgram(prog)
//p.EnableDebug()
var lastOut int
go func() {
for {
if !p.NeedsOutput() && !p.NeedsInput() {
time.Sleep(1)
} else if p.NeedsOutput() {
lastOut = getOutput(p)
fmt.Print(string(byte(lastOut)))
} else if p.NeedsInput() {
instructions := "NOT A J\nNOT B T\nOR T J\nNOT C T\nOR T J\nAND D J\nAND E T\nOR H T\nAND T J\nRUN\n"
for _, v := range []byte(instructions) {
fmt.Print(string(v))
p.Input(int(v))
}
}
}
/*
fmt.Println(getOutput(p))
return
*/
}()
p.Run()
fmt.Println("Damage:", lastOut)
}
func getOutput(p *intcode.Program) int {
for !p.NeedsOutput() {
time.Sleep(1)
}
return p.Output()
}