DEV Community

Discussion on: Advent of Code 2019 Solution Megathread - Day 25: Cryostasis

Collapse
 
jbristow profile image
Jon Bristow • Edited

I didn't actually write more than a handful of lines of new code!

Mostly, I just reused the breakout clone (ascii output to screen) and added a blocking stdin read in the "input" section.

private fun Cryostasis.sendInput(): Cryostasis {
    return state.fold(
        ifLeft = { this },
        ifRight = {
            when {
                it.waitingForInput -> {
                    if (initalCommands.isNotEmpty()) {
                        it.inputs.addAll(initalCommands.pop().map(Char::toLong))
                    } else {
                        val enteredString = readLine()
                        it.inputs.addAll(enteredString!!.map(Char::toLong))
                        it.inputs.add(10L)
                    }
                    this.copy(saveState = code.toMap())
                }
                else -> {
                    this
                }
            }
        }
    )
}

As you can see, after game-overing myself a few times (Eaten by a grue! You'd think I'd learn after all these years!) I found it necessary to pipe in a pre-formatted set of inputs to bootstrap me back to the state I was in before.

I played around trying to see if there was an obvious way to cheat, but in the end I just wandered around and then did a manual DFS of the items to get my way through the security checkpoint.

Merry Christmas everyone! Thanks for sharing your work with me! I hope you had fun!

Collapse
 
jbristow profile image
Jon Bristow

Here's a rudimentary map I made in excel: i.imgur.com/hW2bFJw.png