Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
0^n1^n2^n的Python图灵机_Python_Turing Machines - Fatal编程技术网

0^n1^n2^n的Python图灵机

0^n1^n2^n的Python图灵机,python,turing-machines,Python,Turing Machines,我收到了“创建一台图灵机以识别0^n1^n2^n形式的字符串”的说明。这意味着如果字符串的形式正确,图灵机将在空白磁带上停止,而如果它的形式不正确,它将在非空白单元格上停止 我知道图灵机器如何工作的基础知识,但不知道如何用Python实现图灵机器。我在网上找到的任何例子似乎都非常复杂,有多个类,什么都有。我不认为这对我的申请是完全必要的 我发现此问题的以下psuedocode: On input string w while there are unmarked 0s, do

我收到了“创建一台图灵机以识别0^n1^n2^n形式的字符串”的说明。这意味着如果字符串的形式正确,图灵机将在空白磁带上停止,而如果它的形式不正确,它将在非空白单元格上停止

我知道图灵机器如何工作的基础知识,但不知道如何用Python实现图灵机器。我在网上找到的任何例子似乎都非常复杂,有多个类,什么都有。我不认为这对我的申请是完全必要的

我发现此问题的以下psuedocode:

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

然而,在我看来,实现这个精确的伪代码并不会真正成为一个合法的图灵机。我走错方向了吗?非常感谢您的指导。

对于我来说,pesudo代码似乎是正确的,如果您向我们展示了一个对于一个不太复杂的问题可以接受的示例,可能会有所帮助,我不知道python的TM中到底接受了什么。

为了实现该代码,您将如何在给定的字符串中“标记”一项?我不明白图灵机器的“头”或“带”是什么样的。只要把3看成是“标记”字符。只要你想标记一个空格,就把它设为3。你甚至不需要知道什么是在标记下,所以它应该工作得很好。