Question

I was given the instructions "Create a Turing machine to recognize string of the form 0^n1^n2^n. This means that if the string is of the correct form, the Turing machine stops on a blank tape, while if it is not of the correct form it stops on a non-blank cell".

I know the basics of how a Turing machine works, but no idea how to implement one in Python. Any examples I've found online seem very complex, with multiple classes and everything. I don't think that is completely necessary or expected for my application.

I found the following psuedocode for this problem:

On input string w
   while there are unmarked 0s, do
      Mark the left most 0
      Scan right to reach the leftmost unmarked 1;
         if there is no such 1 then crash
      Mark the leftmost 1
      Scan right to reach the leftmost unmarked 2;
         if there is no such 2 then crash
      Mark the leftmost 2
   done
   Check to see that there are no unmarked 1s or 2s;
      if there are then crash
   accept

However, it seems to me that implementing this exact pseudocode would not really end up being a legitimate turing machine. Am I going about this the wrong way? Any guidance is appreciated.

Was it helpful?

Solution

That pesudo code seems correct to me, it might help if you showed us an example of what would be acceptable for a less complex problem, I don't know exactly what is accepted in the TM in python.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top