Skip to content

Commit

Permalink
Turing code
Browse files Browse the repository at this point in the history
  • Loading branch information
yves-chevallier committed Sep 16, 2024
1 parent de2a6fc commit 14a7ca7
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Handbook

![.github/workflows/ci.yml](https://github.com/heig-tin-info/handbook/workflows/.github/workflows/ci.yml/badge.svg?branch=master)
![.github/workflows/ci.yml](https://github.com/heig-tin-info/handbook/workflows/.github/workflows/ci.yml/badge.svg)

![version](https://img.shields.io/github/v/release/heig-tin-info/handbook)
![downloads](https://img.shields.io/github/downloads/heig-tin-info/handbook/latest/total)
Expand Down
3 changes: 0 additions & 3 deletions docs/assets/src/.clang-format

This file was deleted.

Binary file removed docs/assets/src/c99
Binary file not shown.
Binary file removed docs/assets/src/parser
Binary file not shown.
23 changes: 23 additions & 0 deletions docs/assets/src/turing-machine/README.md
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:
```
26 changes: 26 additions & 0 deletions docs/assets/src/turing-machine/turing.c
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);
}
27 changes: 0 additions & 27 deletions docs/assets/src/turing.c

This file was deleted.

Binary file not shown.

0 comments on commit 14a7ca7

Please sign in to comment.