-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de2a6fc
commit 14a7ca7
Showing
8 changed files
with
50 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Turing Machine Simulator | ||
|
||
This is a simple Turing Machine simulator written in C. The program reads a number in binary and adds one to it. | ||
|
||
```bash | ||
gcc turing.c -o turing | ||
echo "100101101011" >> ./turing | ||
100101101100 | ||
``` | ||
|
||
The algorithm is the following: | ||
|
||
```text | ||
input: '101' | ||
table: | ||
right: | ||
[1,0]: R | ||
' ' : {L: carry} | ||
carry: | ||
1 : {write: 0, L} | ||
[0,' ']: {write: 1, L: done} | ||
done: | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#define BAND_SIZE 1000 | ||
|
||
int main() { | ||
char tape[BAND_SIZE] = {0}; | ||
int head = BAND_SIZE / 2; | ||
|
||
scanf("%s", tape + head); | ||
|
||
// Add algorithm here | ||
char c = tape[head]; | ||
while (c == '0' || c == '1') c = tape[++head]; | ||
c = tape[--head]; | ||
while (c == '1') { | ||
tape[head--] = '0'; | ||
c = tape[head]; | ||
} | ||
tape[head] = '1'; | ||
|
||
// Search first non-null character | ||
while (tape[head]) head--; | ||
head++; | ||
printf("%s\n", tape + head); | ||
} |
This file was deleted.
Oops, something went wrong.
Binary file not shown.