Day 21 solution

Hopefully my logic is explained well enough in the comments for this one. We're just layering more programming languages on top of other programming languages. This is how you anger the computer gods and bring about the AI singularity.

I also made some general tweaks to the Intcode machine to make ASCII intcode machines dead simple to deal with. Is it worth the extra branches for each input and output instruction in the interpreter? Probably not...but I was never going to win any speed competitions anyway.
This commit is contained in:
2022-07-18 09:20:29 -05:00
parent effd94c09b
commit e5dd6a6ca3
5 changed files with 125 additions and 8 deletions

View File

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