This repository contains a simple Python implementation of a Turing Machine simulator that checks whether a binary string contains an even number of 1's. The simulation is interactive and demonstrates the step-by-step operation of a Turing Machine.
- Simulates a Turing Machine for binary strings.
- Accepts if the input has an even number of 1's, rejects otherwise.
- Step-by-step interactive simulation with clear state and tape visualization.
turing machine.py: Main Python script containing the Turing Machine simulator and example runs.requirements.txt: (Currently empty) No external dependencies required..gitignore: Standard Python ignores.
- Python 3.6 or higher (for f-string support).
- Clone the repository:
git clone <repo-url> cd <repo-directory>
- Run the simulator:
python "turing machine.py" - Follow the prompts:
- The script will run two example simulations: one with an even number of 1's and one with an odd number.
- Press Enter to step through each transition.
- The Turing Machine reads the input tape from left to right.
- It switches between two states (
q0andq1) depending on the symbol read (0or1). - When the end of the input (blank symbol
B) is reached:- If in state
q0, the input is accepted (even number of 1's). - If in state
q1, the input is rejected (odd number of 1's).
- If in state
Testing Turing Machine for Even Number of 1's
==================================================
Input: 1010
Starting simulation...
Press Enter to continue each step...
Step 1:
State: q0
Tape: [1]010B
Reading symbol: 1
Action: Move to q1, move right
...
Final state: q_accept
Result: ACCEPT - The input has an even number of 1's
This project is provided for educational purposes.