[英]Design state diagram of turing machine that multiplies a unary number by 2
If the input is 1^n, the output should be in the format X^n 1^2n. 如果输入为1 ^ n,则输出格式应为X ^ n 1 ^ 2n。 For example if the input is 11, the output should be XX1111.
例如,如果输入为11,则输出应为XX1111。 Note A number N is represented as a unary number by repeating the digit 1 , N number of times.
注意数字N通过重复数字1(N次)表示为一元数。
Our strategy will be to replace the last 1
on the input tape with X
, write two 1
s to the right, and repeat with the next 1
to the left of all X
s, until we run out of 1
s to the left of X
s. 我们的策略是将输入磁带上的最后
1
替换为X
,在右侧写两个1
s,然后在所有X
的左边重复下一个1
,直到我们在X
的左边用尽1
s s。
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
Example: 111
示例:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.