将一元数乘以2

时间:2018-01-03 18:29:21

标签: automata finite-automata turing-machines turing

如果输入为1 ^ n,则输出的格式应为X ^ n 1 ^ 2n。例如,如果输入为11,则输出应为XX1111。 注意 通过重复数字1,N次,将数字N表示为一元数。

1 个答案:

答案 0 :(得分:0)

我们的策略是用1替换输入磁带上的最后X,向右写两个1,然后用下一个1重复所有X的左侧,直到1 s左侧的X用完为止。

q    t    q'    t'    d
-----------------------
q0   #    hA    #     -        // accept the empty tape

q0   1    q1    1     right    // move to the end of input
q1   1    q1    1     right    // if the tape is not empty
q1   #    q2    #     left

q2   X    q2    X     left     // look for the last 1 remaining
q2   1    q3    X     right    // from the input and cross it out.
q2   #    hA    #     -        // accept if no more 1s

q3   X    q3    X     right    // move right until you find a
q3   1    q3    1     right    // blank cell. then, write two
q3   #    q4    1     right    // 1s to the tape.
q4   #    q5    1     left

q5   1    q5    1     left     // move left until you find Xs
q5   X    q2    X     left     // then repeat as above

示例:111

#111#######  =>  #111#######  =>  #111#######  =>  #111#######  =>
 ^q0               ^q1               ^q1               ^q1

#111#######  =>  #11X#######  =>  #11X1######  =>  #11X11#####  =>
   ^q2               ^q3               ^q4             ^q5

#11X11#####  =>  #11X11#####  =>  #1XX11#####  =>  #1XX11#####  =>
   ^q5             ^q2               ^q3               ^q3

#1XX11#####  =>  #1XX11#####  =>  #1XX111####  =>  #1XX1111###  =>
     ^q3               ^q3               ^q4             ^q5

#1XX1111###  =>  #1XX1111###  =>  #1XX1111###  =>  #1XX1111###  =>
     ^q5             ^q5             ^q5             ^q2

#1XX1111###  =>  #XXX1111###  =>  #XXX1111###  =>  #XXX1111###  =>
 ^q2               ^q3               ^q3               ^q3

#XXX1111###  =>  #XXX1111###  =>  #XXX1111###  =>  #XXX1111###  =>
     ^q3               ^q3               ^q3               ^q3

#XXX11111##  =>  #XXX111111#  =>  #XXX111111#  =>  #XXX111111#  =>
         ^q4             ^q5             ^q5             ^q5

#XXX111111#  =>  #XXX111111#  =>  #XXX111111#  =>  #XXX111111#  =>
     ^q5             ^q5             ^q5             ^q2

#XXX111111#  =>  #XXX111111#  =>  #XXX111111#
 ^q2             ^q2              ^hA