Browse Source

2019 Day 17 Complete

master
Brian Buller 2 years ago
parent
commit
39f5680ff3
  1. 2
      2019/day15/main.go
  2. 11
      2019/day17/main.go
  3. 34
      2019/day17/part2.go

2
2019/day15/main.go

@ -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()

11
2019/day17/main.go

@ -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")

34
2019/day17/part2.go

@ -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)
}

Loading…
Cancel
Save