# Path: automata/tm/configuration.py
# class TMConfiguration(collections.namedtuple(
#     'TMConfiguration',
#     ['state', 'tape']
# )):
#     """A Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tape
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         print('{current_state}: {tape}\n{current_position}'.format(
#             current_state=self.state,
#             tape=''.join(self.tape).rjust(
#                 len(self.tape),
#                 self.tape.blank_symbol),
#             current_position='^'.rjust(
#                 self.tape.current_position + len(self.state) + 3
#             ),
#         ))
# 
# Path: automata/tm/tape.py
# class TMTape(collections.namedtuple(
#     'TMTape',
#     ['tape', 'blank_symbol', 'current_position']
# )):
#     """A Turing machine tape."""
# 
#     def __new__(cls, tape, *, blank_symbol, current_position=0):
#         """Initialize a new Turing machine tape."""
#         tape = list(tape)
#         # Make sure that there's something under the cursor.
#         while len(tape) <= current_position:
#             tape.append(blank_symbol)
#         tape = tuple(tape)
#         return super(TMTape, cls).__new__(
#             cls, tape, blank_symbol, current_position
#         )
# 
#     def load_symbols(self, input_str, head):
#         """Loads a given string in tape and sets the head to the given
#         value."""
#         return TMTape(
#             list(input_str),
#             blank_symbol=self.blank_symbol,
#             current_position=head
#         )
# 
#     def read_symbol(self):
#         """Read the symbol at the current position in the tape."""
#         return self.tape[self.current_position]
# 
#     def write_symbol(self, new_tape_symbol):
#         """Write the given symbol at the current position in the tape."""
#         tape_elements = list(self.tape)
#         tape_elements[self.current_position] = new_tape_symbol
#         return TMTape(
#             tape_elements,
#             blank_symbol=self.blank_symbol,
#             current_position=self.current_position
#         )
# 
#     def move(self, direction):
#         """Move the tape to the next symbol in the given direction."""
#         # Copy stuff.
#         new_tape = list(self.tape)
#         new_position = self.current_position
#         if direction == 'R':
#             new_position += 1
#         elif direction == 'N':
#             pass
#         elif direction == 'L':  # pragma: no branch
#             new_position -= 1
#         # Make sure that the cursor doesn't run off the end of the tape.
#         if new_position == -1:
#             new_tape.insert(0, self.blank_symbol)
#             new_position += 1
#         if new_position == len(new_tape):
#             new_tape.append(self.blank_symbol)
#         return TMTape(
#             new_tape,
#             blank_symbol=self.blank_symbol,
#             current_position=new_position
#         )
# 
#     def copy(self):
#         return TMTape(list(self.tape).copy(),
#                       blank_symbol=self.blank_symbol,
#                       current_position=self.current_position)
# 
#     def get_symbols_as_str(self):
#         return "".join(self.tape)
# 
#     def __len__(self):
#         """Return the number of symbols on the tape."""
#         return len(self.tape)  # TODO: do we count the blank symbols?
# 
#     def __iter__(self):
#         """Return an interator for the tape."""
#         return iter(self.tape)
# 
#     def __repr__(self):
#         """Return a string representation of the tape."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, ''.join(self.tape), self.current_position
#         )


import copy
import automata.base.exceptions as exceptions
import automata.tm.exceptions as tm_exceptions
import automata.tm.tm as tm
from automata.tm.configuration import TMConfiguration
from automata.tm.tape import TMTape
    def _has_accepted(self, configuration):
        """Check whether the given config indicates accepted input."""
        return configuration.state in self.final_states

    def _get_next_configuration(self, old_config):
        """Advance to the next configuration."""
        transitions = {self._get_transition(
            old_config.state,
            old_config.tape.read_symbol()
        )}
        if None in transitions:
            transitions.remove(None)
        if len(transitions) == 0:
            raise exceptions.RejectionException(
                'The machine entered a non-final configuration for which no '
                'transition is defined ({}, {})'.format(
                    old_config.state, old_config.tape.read_symbol()))
        tape = old_config.tape
        (new_state, new_tape_symbol,
            direction) = transitions.pop()
        tape = tape.write_symbol(new_tape_symbol)
        tape = tape.move(direction)
        return TMConfiguration(new_state, tape)

    def read_input_stepwise(self, input_str):
        """
        Check if the given string is accepted by this Turing machine.

        Yield the current configuration of the machine at each step.
        """

# Path: automata/tm/configuration.py
# class TMConfiguration(collections.namedtuple(
#     'TMConfiguration',
#     ['state', 'tape']
# )):
#     """A Turing machine configuration."""
# 
#     def __repr__(self):
#         """Return a string representation of the configuration."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, self.state, self.tape
#         )
# 
#     def print(self):
#         """Print the machine's current configuration in a readable form."""
#         print('{current_state}: {tape}\n{current_position}'.format(
#             current_state=self.state,
#             tape=''.join(self.tape).rjust(
#                 len(self.tape),
#                 self.tape.blank_symbol),
#             current_position='^'.rjust(
#                 self.tape.current_position + len(self.state) + 3
#             ),
#         ))
# 
# Path: automata/tm/tape.py
# class TMTape(collections.namedtuple(
#     'TMTape',
#     ['tape', 'blank_symbol', 'current_position']
# )):
#     """A Turing machine tape."""
# 
#     def __new__(cls, tape, *, blank_symbol, current_position=0):
#         """Initialize a new Turing machine tape."""
#         tape = list(tape)
#         # Make sure that there's something under the cursor.
#         while len(tape) <= current_position:
#             tape.append(blank_symbol)
#         tape = tuple(tape)
#         return super(TMTape, cls).__new__(
#             cls, tape, blank_symbol, current_position
#         )
# 
#     def load_symbols(self, input_str, head):
#         """Loads a given string in tape and sets the head to the given
#         value."""
#         return TMTape(
#             list(input_str),
#             blank_symbol=self.blank_symbol,
#             current_position=head
#         )
# 
#     def read_symbol(self):
#         """Read the symbol at the current position in the tape."""
#         return self.tape[self.current_position]
# 
#     def write_symbol(self, new_tape_symbol):
#         """Write the given symbol at the current position in the tape."""
#         tape_elements = list(self.tape)
#         tape_elements[self.current_position] = new_tape_symbol
#         return TMTape(
#             tape_elements,
#             blank_symbol=self.blank_symbol,
#             current_position=self.current_position
#         )
# 
#     def move(self, direction):
#         """Move the tape to the next symbol in the given direction."""
#         # Copy stuff.
#         new_tape = list(self.tape)
#         new_position = self.current_position
#         if direction == 'R':
#             new_position += 1
#         elif direction == 'N':
#             pass
#         elif direction == 'L':  # pragma: no branch
#             new_position -= 1
#         # Make sure that the cursor doesn't run off the end of the tape.
#         if new_position == -1:
#             new_tape.insert(0, self.blank_symbol)
#             new_position += 1
#         if new_position == len(new_tape):
#             new_tape.append(self.blank_symbol)
#         return TMTape(
#             new_tape,
#             blank_symbol=self.blank_symbol,
#             current_position=new_position
#         )
# 
#     def copy(self):
#         return TMTape(list(self.tape).copy(),
#                       blank_symbol=self.blank_symbol,
#                       current_position=self.current_position)
# 
#     def get_symbols_as_str(self):
#         return "".join(self.tape)
# 
#     def __len__(self):
#         """Return the number of symbols on the tape."""
#         return len(self.tape)  # TODO: do we count the blank symbols?
# 
#     def __iter__(self):
#         """Return an interator for the tape."""
#         return iter(self.tape)
# 
#     def __repr__(self):
#         """Return a string representation of the tape."""
#         return '{}(\'{}\', {})'.format(
#             self.__class__.__name__, ''.join(self.tape), self.current_position
#         )


# Path: automata/tm/dtm.py
import copy
import automata.base.exceptions as exceptions
import automata.tm.exceptions as tm_exceptions
import automata.tm.tm as tm
from automata.tm.configuration import TMConfiguration
from automata.tm.tape import TMTape

    def _has_accepted(self, configuration):
        """Check whether the given config indicates accepted input."""
        return configuration.state in self.final_states

    def _get_next_configuration(self, old_config):
        """Advance to the next configuration."""
        transitions = {self._get_transition(
            old_config.state,
            old_config.tape.read_symbol()
        )}
        if None in transitions:
            transitions.remove(None)
        if len(transitions) == 0:
            raise exceptions.RejectionException(
                'The machine entered a non-final configuration for which no '
                'transition is defined ({}, {})'.format(
                    old_config.state, old_config.tape.read_symbol()))
        tape = old_config.tape
        (new_state, new_tape_symbol,
            direction) = transitions.pop()
        tape = tape.write_symbol(new_tape_symbol)
        tape = tape.move(direction)
        return TMConfiguration(new_state, tape)

    def read_input_stepwise(self, input_str):
        """
        Check if the given string is accepted by this Turing machine.

        Yield the current configuration of the machine at each step.
        """

        current_configuration = TMConfiguration(