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/example2.cpp

45 lines
988 B
C++
Raw Normal View History

2022-11-26 05:03:22 +01:00
#include <iostream>
#include "turing.cpp"
#include "utils/print.cpp"
enum values {
yes = 1,
no = 0,
blank = 6,
};
int main() {
auto def = new Turing::Definition<char, values> {
.defaultState = 'a',
.defaultValue = values::blank,
.instructions = {
// multiply binary represented number by 2
Turing::Instruction('a', values::yes, 'a', values::yes, Turing::Movement::right),
Turing::Instruction('a', values::no, 'a', values::no, Turing::Movement::right),
Turing::Instruction('a', values::blank, 'b', values::no, Turing::Movement::right),
}
};
auto turing = new Turing::Machine(def);
turing->setTape({
values::no,
values::no,
values::yes,
values::no,
values::yes,
values::no,
values::yes,
values::no
});
print(turing);
std::cout << '\n';
while(turing->tick());
print(turing);
return 0;
}