Shall We Play A Game?
Disclaimer: This game and its script is adopted from the puzzles of the Advent of Code 2019.
Prologue
Santa Claus has become stranded at the edge of the Solar System while delivering presents to other planets! Your mission is to help him return to Earth in time to save Christmas by fixing his ship.
As you approach Santa’s ship, your sensors report the internal temperature is -40 degrees! The airlock door is locked with a code (password); your best option is to send in a small droid to investigate the situation. You attach your ship to Santa’s, break a small hole in the hull, and let the droid run in before you seal it up again. Before your ship starts freezing, you detach your ship and set it to automatically stay within range of Santa’s ship.
This droid can follow basic instructions and report on its surroundings. As the droid moves through its environment, it will describe what it encounters. When it says Command?
, you can give it a single instruction – all possible instructions are:
- Movement via
north
,south
,east
, orwest
. - To take an item the droid sees in the environment, use the command
take <name of item>
. For example, if the droid reports seeing ared ball
, you can pick it up withtake red ball
. - To drop an item the droid is carrying, use the command
drop <name of item>
. For example, if the droid is carrying agreen ball
, you can drop it withdrop green ball
. - At any time, to get a list of all of the items the droid is currently carrying, use the command
inv
(for “inventory”).
Note that commands should all be in lower case and other characters aren’t allowed – instructions must be provided precisely.
Santa’s ship uses pressure-sensitive floors to determine the identity of droids and crew members. The standard configuration is for all droids to weigh exactly a predetermined number for them to get past such a sensor. Your droid might be able to reach the correct weight by carrying a certain combination of items collected from exploring the environment.
Therefore, your challenge now is to control the droid to explore the ship and collect the right combination of items in order to pass the pressure-sensitive floor. Once passed it, you will find the password for the main airlock that desperately needs repairing. What is the password?
The game
The game is embedded in the app below. After the initial welcome message, type anything to begin. As your droid moves about the environment, it will explore the different chambers in the ship denoted by == <Name of Chamber> ==
. The environment description is in green text, while your command is in yellow. Type your command in the message box and hit Enter or click Send to execute it. A system message (prompt) will then be returned in response to simulate the command being carried out (if it’s valid). At any time, if you feel like starting over, simply refresh your browser to reset the game.
At any point during the game, the available directions (doors) and/or items to take are listed by - <name of item or direction>
. You can only take what is available then and there. You can only give one command at a time. The game ends when the returned prompt ends with the message Program completed.
, in which case either you have successfully solved it or have picked up a dangerous item (more in next section). If it’s the former, the password will be shown in the prompt – congratulations! If it’s the latter, simply reset the game to start over as many times as you wish.
Hints
You may find the following hints helpful towards successfully solving the puzzle:
- Consider the “environment” that the droid explores as a graph, where each chamber is a node and each door that leads the next chamber is an edge.
- This graph should be undirected as you can use an edge (door) to exit a given node and the opposite (direction-wise) edge to re-enter it from its neighboring node.
- The graph is also unweighted as the cost of each edge is uniform – hence, using BFS traversal would suffice to find the shortest path from one node to another (if you ever need to).
- However, you will first need to explore all the nodes in the graph and collect all the items that aren’t dangerous – DFS traversal can do this job nicely.
- You might as well use a pencil and paper to map out the graph as you explore it (e.g., to remember each node by its name and if it has been visited, etc.)
- There are certain dangerous items that when taken will end the game prematurely (or you may get stuck in an infinite loop). Good news is there aren’t so many of them, and you can know which one is dangerous by trial and error (and remember not to take it again!)
- As you approach the pressure-sensitive floor with all the items you have collected, you may need to generate all possible combinations of them (i.e., to take or not to take) and see which one would pass. Obviously, the number of items to be taken is at least 2 and less than the maximal number of items (that can be taken) – the optimal number should be somewhere in between. The
drop
command would come in handy here to drop unwanted items.