Tm is a simplest of a computer, and the start of modern computers.
You have a strip of memory locations which can be either 0 or 1
Location | 0000 | 0001 | 0002 | ... | 5000 |
---|---|---|---|---|---|
Value | 0 | 1 | 1 | ... | 0 |
Assume Turing machine as a pointer. It will always point to one of the location.
Now a TM can move left or move right by one.
If it is currently pointing towards 3068. And left is used it will point to 3067.
The left character is <
.
<<<<
stands for 4 lefts.
Similarly it can move right on the strip.
The right character is >
.
>>>>>>
stands for 6 lefts.
You are able to read the value at current memory location by using .
>>>.
Move 3 right and read the value.
You can toggle the value at current location by using ^
>>>.^.
Move 3 right, read, toggle the value and read again.
Check if a value of current memory 1. ?
is the character.
If so it will execute the code following it.
>>?.
Move 2 right . If the value is 1, then read it.
?>>^<<
If current values is 1, move 2 left toggle the value, and come back to original position.
When you want to use only certain commands after the if statement./
is the character.
?^./>.
If the current character is 1. Toggle it and read it. Then Move right and read the value.
[0] 1 [1] 0
Code after / will be always executed.