Turing machine halting in ten steps
Time limit1sMemory limit256 MB
Simulate a Turing machine for at most 10 steps on each query tape and report whether it reaches the halting state.
- Level
Easy3 of 10
- Topics
- Simulation, Implementation, Array, Brute force
- Solved
- No attempts yet
Problem
Alan Mathison Turing was a British mathematician and computer scientist. He proposed the Turing machine, an abstract machine that defines computation through a mathematical model.
A Turing machine has a finite set of states, a tape that runs without end in both directions, a set of symbols that can be written on the tape, and a set of transition rules. The machine begins in its initial state with the head resting on one cell of the tape. On every step it reads its current state and the symbol under the head, and the matching transition rule tells it which symbol to write into that cell, which direction to move the head, and which state to enter next. The machine writes the symbol first and moves the head afterwards.
The halting problem asks whether a given Turing machine eventually halts on a given input tape or runs forever. No algorithm settles that question for every machine. Deciding whether a machine halts within 10 steps is a different matter, and it is decidable. That is the answer you have to produce.
Input
The first line has one integer (), the number of test cases.
Each test case starts with the description of one Turing machine. The first line of the description has one integer (), the number of states. State is the initial state and state is the only halting state, so the machine halts the moment it enters state . If , the machine sits in the halting state before it takes a single step.
The next lines hold the transition rules of states through . State has no transition rule. Only the three symbols , and appear on the tape. Line contains three triples of the form (x, y, z) separated by a space, and they are the rules of state for the symbols , and in that order. Inside a triple, is the next state (), is the direction the head moves, where is right and is left, and is the symbol written into the current cell before the head moves. For example, the second triple on the fifth line is the rule of state when the head reads symbol .
The line after the machine has one integer (), the number of queries. Each query is written on one line. It starts with the number of input symbols (), followed by symbols. Those symbols go onto consecutive cells of the tape in the given order, and the head starts on the first of them. A query contains only the symbols and , because symbol stands for a blank cell. Every cell before the given symbols and every cell after them holds . The query 3 1 0 0, for instance, makes the tape look like ... 2 2 2 1 0 0 2 2 2 ... with the head on the symbol , and the blanks run without end in both directions. When the whole tape is blank and the head starts on a blank cell.
Output
For each test case, print Machine #N: on its own line, where is the number of the test case counted from . Then, in the order the queries are given, print one line per query: yes if the machine halts within steps, and no if it does not. A machine that halts on step has halted within steps.