https://github.com/arya2004/turing-machine
Turing Machine in C
https://github.com/arya2004/turing-machine
Last synced: 4 months ago
JSON representation
Turing Machine in C
- Host: GitHub
- URL: https://github.com/arya2004/turing-machine
- Owner: arya2004
- License: mit
- Created: 2024-12-06T16:15:49.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-08T13:02:17.000Z (over 1 year ago)
- Last Synced: 2025-04-05T03:14:32.332Z (about 1 year ago)
- Language: C
- Homepage:
- Size: 358 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Turing Machine in C
This repository contains an implementation of a **Turing Machine** written in C. A Turing Machine is a mathematical model of computation that manipulates symbols on a strip of tape according to a table of rules. It is used to understand the limits of what can be computed.
## Inspiration
This project was inspired by the creation of a [Turing Machine Calculator in C](https://github.com/arya2004/turing-machine-calculator-simulator). While working on that project, the idea of developing a **universal Turing Machine simulator** emerged. The goal of this project is to provide a generalized implementation that supports customizable configurations and can simulate any Turing Machine defined by a valid set of rules.
## Features
- **Flexible Tape Initialization**: Random, default, or user-defined initial tape configurations.
- **Customizable Instructions**: Supports user-defined transition states through input files.
- **Execution Logging**: Outputs tape state and head position during execution.
- **Memory Management**: Dynamically expands the tape as needed.
## Usage
### Build Instructions
#### With CMake
```bash
mkdir build
cd build
cmake ..
make
```
#### Without CMake
Compile the code using GCC or any compatible C compiler:
```bash
mkdir build
gcc -o build/turing_machine src/main.c
```
### Running the Program
#### Syntax:
```bash
./turing_machine
```
- ``: File containing Turing Machine instructions.
- ``: (Optional) Initial tape configuration.
#### Example:
1. With default tape:
```bash
./turing_machine instructions.turing
```
2. With custom tape:
```bash
./turing_machine instructions.turing "11001"
```
### Input File Format
The `.turing` instruction file should follow the format:
```
```
- **state**: The current state (integer).
- **expected_symbol**: Symbol to read at the head.
- **write_symbol**: Symbol to write at the head.
- **direction**: Direction to move the head (`R`, `L`, or `H` for Halt).
- **next_state**: Next state to transition to.
#### Example:
```
0 _ 1 R 1
1 1 0 L 0
1 _ _ H 0
```
### Outputs
- Final tape state.
- Head position.
- Error messages for out-of-bound conditions or invalid instructions.
---
## Limitations
- The tape must have sufficient memory; expansion occurs dynamically but is limited by system constraints.
- Instructions must cover all possible states and symbols to avoid runtime errors.
---
## Contributing
1. Fork the repository.
2. Create a new feature branch: `git checkout -b feature-name`.
3. Commit your changes: `git commit -m "Add feature-name"`.
4. Push to the branch: `git push origin feature-name`.
5. Open a Pull Request.
---
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.