This repository has been archived on 2022-11-26. You can view files and clone it, but cannot push or open issues or pull requests.
turing/example1.cpp
2022-11-26 05:03:22 +01:00

53 lines
No EOL
1 KiB
C++

#include <iostream>
#include <vector>
#include "turing.cpp"
#include "utils/operators.cpp"
#include "utils/print.cpp"
int main() {
auto def = new Turing::Definition<char, char> {
.defaultState = '0',
.defaultValue = '#',
.instructions = {
// Palindrome checker
// if the last state is R or 0, then it is a palindrome
// otherwise it is not
"00a0r"_i,
"01b1r"_i,
"a0a0r"_i,
"a1a1r"_i,
"b0b0r"_i,
"b1b1r"_i,
"a#A#l"_i,
"b#B#l"_i,
"A0r#l"_i,
"B1r#l"_i,
"r0r0l"_i,
"r1r1l"_i,
"r#R#r"_i,
"R00#r"_i,
"R10#r"_i,
},
};
auto turing = new Turing::Machine<char, char>(def);
turing->setTape("0010110100"_v);
print(turing);
int i = 0;
while (i++ < 100) {
if (!turing->tick()) break;
print(turing);
}
print(turing);
return 0;
}