2019 Day 17 Complete

This commit is contained in:
Brian Buller 2019-12-18 14:21:01 -06:00
parent 5d8cf97902
commit 39f5680ff3
3 changed files with 29 additions and 18 deletions

View File

@ -123,6 +123,7 @@ func BFS(start, goal *BFSNode) (bool, []*BFSNode) {
var queue, explored []*BFSNode
queue = append(queue, start)
if start == goal {
fmt.Println(queue)
return true, queue
}
explored = append(explored, start)
@ -131,6 +132,7 @@ func BFS(start, goal *BFSNode) (bool, []*BFSNode) {
if len(queue) > 1 {
current, queue = queue[0], queue[1:]
if current == goal {
fmt.Println(explored)
return true, explored
} else {
children := current.getChildren()

View File

@ -7,6 +7,17 @@ import (
var layout [][]byte
/*
L,4,L,4,L,10,R,4,R,4,L,4,L,4,R,8,R,10,L,4,L,4,L,10,R,4,R,4,L,10,R,10,L,4,L,4,L,10,R,4,R,4,L,10,R,10,R,4,L,4,L,4,R,8,R,10,R,4,L,10,R,10,R,4,L,10,R,10,R,4,L,4,L,4,R,8,R,10
A,B,A,C,A,C,B,C,C,B
A=L,4,L,4,L,10,R,4
B=R,4,L,4,L,4,R,8,R,10
C=R,4,L,10,R,10
*/
func main() {
pt := helpers.GetArgNumber(1)
prog := intcode.ReadIntCodeFile("input")

View File

@ -11,23 +11,15 @@ func part2(prog []int) {
p := intcode.NewProgram(prog)
p.SetProgramValueAt(0, 2)
/*
A: L,4,L,4,L,10,R,4,R,4
B: L,4,L,4,R,8,R,10,
A: L,4,L,4,L,10,R,4,R,4
L,10,R,10,
A: L,4,L,4,L,10,R,4,R,4,
L,10,R,10,R,4,
L,4,L,4,R,8,R,10,R,4,
L,10,R,10,R,4,
L,10,R,10,R,4,
B: L,4,L,4,R,8,R,10
*/
var input []string
input = append(input, "A,B,A,C"+string(byte(10)))
input = append(input, "L,4,L,4,L,10,R,4,R,4"+string(byte(10)))
input = append(input, "L,4,L,4,R,8,R,10"+string(byte(10)))
input = append(input, "L,10"+string(byte(10)))
// Main Sequence
input = append(input, "A,B,A,C,A,C,B,C,C,B"+string(byte(10)))
// A
input = append(input, "L,4,L,4,L,10,R,4"+string(byte(10)))
// B
input = append(input, "R,4,L,4,L,4,R,8,R,10"+string(byte(10)))
// C
input = append(input, "R,4,L,10,R,10"+string(byte(10)))
go func() {
printAllOutput(p)
@ -38,7 +30,7 @@ func part2(prog []int) {
for !p.NeedsInput() {
time.Sleep(1)
}
p.Input(int('y'))
p.Input(int('n'))
for !p.NeedsInput() {
time.Sleep(1)
}
@ -87,7 +79,13 @@ func printAllOutput(p *intcode.Program) {
return
}
if p.NeedsOutput() {
fmt.Print(string(p.Output()))
out := p.Output()
switch out {
case '#', '.', DIR_N, DIR_E, DIR_S, DIR_W:
fmt.Print(string(out))
default:
fmt.Println(out)
}
}
time.Sleep(1)
}