Day 21 setup
Plus some tweaks to make ASCII IntCode machines slightly easier to use. I need to figure out some good criteria for coding this robot thing to avoid gaps of all sizes. #..#.# is the first thing I'm seeing that's giving me trouble, we'd need to know 4 squares ahead of that little island that it was coming since that's how long it takes to jump and come back down. But we can't jump too soon if the gap is actually 3 wide, for example, or if the gap on the other side of the island is also going to be a problem. Ugh.
This commit is contained in:
@ -48,6 +48,7 @@ type Day17 struct {
|
||||
|
||||
func (d *Day17) Parse() {
|
||||
d.program = u.LoadIntcodeProgram("17p")
|
||||
// d.program.SetDebugASCIIPrint(true)
|
||||
}
|
||||
|
||||
func (d Day17) Num() int {
|
||||
@ -388,9 +389,8 @@ func (d *Day17) Part2() string {
|
||||
row := 0
|
||||
var outputState int
|
||||
var lastOutput int64
|
||||
var instructionStr string
|
||||
d.program.RunIn(func(inputStep int) int64 {
|
||||
return int64(instructionStr[inputStep-1])
|
||||
panic("unexpected read")
|
||||
}, func(val int64, state u.IntcodeProgramState) {
|
||||
rVal := rune(val)
|
||||
if outputState == 0 {
|
||||
@ -401,7 +401,7 @@ func (d *Day17) Part2() string {
|
||||
|
||||
if rVal == '\n' && lastOutput == '\n' {
|
||||
if outputState == 0 {
|
||||
instructionStr = beforeGrid.solvePath(beforeBotLocation, beforeBotFacing)
|
||||
d.program.FeedInputString(beforeGrid.solvePath(beforeBotLocation, beforeBotFacing))
|
||||
}
|
||||
outputState++
|
||||
row = 0
|
||||
|
39
days/21.go
Normal file
39
days/21.go
Normal file
@ -0,0 +1,39 @@
|
||||
package days
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
u "parnic.com/aoc2019/utilities"
|
||||
)
|
||||
|
||||
type Day21 struct {
|
||||
program u.IntcodeProgram
|
||||
}
|
||||
|
||||
func (d *Day21) Parse() {
|
||||
d.program = u.LoadIntcodeProgram("21p")
|
||||
d.program.SetDebugASCIIPrint(true)
|
||||
}
|
||||
|
||||
func (d Day21) Num() int {
|
||||
return 21
|
||||
}
|
||||
|
||||
func (d *Day21) Part1() string {
|
||||
cmds := []string{
|
||||
"NOT D T",
|
||||
"OR T J",
|
||||
"WALK",
|
||||
}
|
||||
instructionStr := strings.Join(cmds, "\n") + "\n"
|
||||
d.program.FeedInputString(instructionStr)
|
||||
|
||||
res := d.program.Run()
|
||||
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, res, u.TextReset)
|
||||
}
|
||||
|
||||
func (d *Day21) Part2() string {
|
||||
return fmt.Sprintf("%s%d%s", u.TextBold, 0, u.TextReset)
|
||||
}
|
Reference in New Issue
Block a user