24 lines
796 B
C
24 lines
796 B
C
#include <stdio.h>
|
|
#include <string.h>
|
|
#include "turing.h"
|
|
|
|
// Simuliert die Turingmaschine zur binären Addition von 1
|
|
void ausfuehren(char *band, int pos) {
|
|
int carry = 1; // Wir wollen +1 addieren → also mit Übertrag starten
|
|
|
|
while (carry && pos >= 0) {
|
|
if (band[pos] == '0') {
|
|
band[pos] = '1'; // 0 + 1 = 1 → fertig
|
|
carry = 0;
|
|
} else if (band[pos] == '1') {
|
|
band[pos] = '0'; // 1 + 1 = 0 mit Übertrag → weiter nach links
|
|
pos--;
|
|
} else if (band[pos] == '#') {
|
|
band[pos] = '1'; // Wenn wir am Ende des Bandes sind und Übertrag haben → neue 1
|
|
carry = 0;
|
|
} else {
|
|
fehler("Ungültiges Zeichen auf dem Band."); // Nur 0, 1 und # sind erlaubt
|
|
}
|
|
}
|
|
}
|