Day 25 solution

Sort of...I mean, you have to play it yourself, but it works. This is a text-based adventure game. The goal is to go around picking up items (except for the 5 items that will kill you/end or hang the game) then find the right combination of items that lets you get through the pressure-sensitive room which terminates the game and gives you the code to enter on the website.

My understanding is that every item has a power-of-2 weight to it, and you have to reach the right set of items to have your weight match the target. The main problem I had was that the output for the pressure room's "heavier" and "lighter" words mean that _other_ droids are heavier/lighter than _you_. Which means if it says "lighter", you need to shed weight/drop stuff, but if it says "heavier", you need to add weight/pick up stuff.

This could be automated in several different ways, but my thought is you'd want to explore the maze, picking up everything that's not the blocked 5 items, find the pressure-sensitive room, and try every combination of items until the process exits, at which point you'd display the number after "by typing" in the final output string. I've stubbed out support for reading the program's output so that you could inspect it and automate if you really wanted to. Right now it just parses the answer from the final output line and prints that by itself.

Items that **should not** be picked up are:

    infinite loop (does what it says to your program)
    molten lava (kills you)
    escape pod (ends the game)
    photons (turns out the lights and causes you to get eaten by a grue)
    giant electromagnet (gets you stuck - no other input works and it cannot be dropped)

This commit's program lets you through if you're carrying:

- ornament
- astrolabe
- weather machine
- food ration

which results in a code of 4206594
This commit is contained in:
2022-07-22 16:56:47 -05:00
parent 5a53ccc865
commit 2b554d1b3d
3 changed files with 63 additions and 0 deletions

61
days/25.go Normal file
View File

@ -0,0 +1,61 @@
package days
import (
"bufio"
"fmt"
"os"
"strings"
u "parnic.com/aoc2019/utilities"
)
type Day25 struct {
program u.IntcodeProgram
}
func (d *Day25) Parse() {
d.program = u.LoadIntcodeProgram("25p")
}
func (d Day25) Num() int {
return 25
}
func (d *Day25) Part1() string {
lastCmdStrings := make([]string, 0)
sb := strings.Builder{}
inReader := bufio.NewReader(os.Stdin)
d.program.SetDebugASCIIPrint(true)
d.program.RunIn(func(inputStep int) int64 {
lastCmdStrings = lastCmdStrings[:0]
text, _ := inReader.ReadString('\n')
d.program.FeedInputString(text[1:])
return int64(text[0])
}, func(val int64, state u.IntcodeProgramState) {
if val == '\n' {
str := sb.String()
if len(str) > 0 {
lastCmdStrings = append(lastCmdStrings, sb.String())
sb.Reset()
}
} else {
sb.WriteRune(rune(val))
}
})
lastString := lastCmdStrings[len(lastCmdStrings)-1]
var answer string
if idx := strings.Index(lastString, " by typing "); idx >= 0 {
startIdx := idx + len(" by typing ")
endIdx := startIdx + strings.Index(lastString[startIdx:], " ")
answer = lastString[startIdx:endIdx]
}
return fmt.Sprintf("Door passcode: %s%s%s", u.TextBold, answer, u.TextReset)
}
func (d *Day25) Part2() string {
return "There is no part 2"
}

1
inputs/25p.txt Normal file

File diff suppressed because one or more lines are too long

View File

@ -58,6 +58,7 @@ var dayMap = []day{
&days.Day22{}, &days.Day22{},
&days.Day23{}, &days.Day23{},
&days.Day24{}, &days.Day24{},
&days.Day25{},
} }
func main() { func main() {