[英]Design a Turing machine that calculates the parity of a binary number
so I have this problem given to me at my university, and I'm really lost about it, I don't know if you can help me cause this is not strictly code, I think I have to doit with digrams and tables by hand. 所以我在大学时遇到了这个问题,我真的很迷失,我不知道您是否可以帮我,因为这不是严格的代码,我想我必须手工处理图和表。
So, the problem is to design a Turing machine that calculates the parity of a binary number. 因此,问题是设计一种可以计算二进制数奇偶校验的图灵机。 If the number of 1's is pair add a 0 at the end, if it is unpair add a 1 at the end. 如果数字为1,则对末尾加0;如果数字为非对,则末尾加1。
Example 例
a) 001001 -> 0010010
b) 101010 -> 1010101
Hoping you can help me, thanks 希望你能帮助我,谢谢
Input: a string x
of binary digits 输入:字符串x
二进制数字
Output: xd
where d
id 0
if #1(x)
is even and 1
if #1(x)
is odd, where #1(x)
is the number of instances of 1 in x
. 输出: xd
,其中d
ID 0
如果#1(x)
是偶数且1
如果#1(x)
是奇数,其中#1(x)
在1实例的数量x
。
Design: we will scan the string from left to right, keeping track of the parity of the number of instances of 1 seen so far. 设计:我们将从左到右扫描字符串,跟踪到目前为止所看到的1个实例的奇偶性。 When we run out of input, we will see which state we are in, write the corresponding final digits, and then halt-accept. 当我们用完输入时,我们将看到我们处于哪个状态,写出相应的最终数字,然后暂停接受。
Implementation: 实现方式:
q t q' t' d comment
q0 0 q0 0 right see a zero, stay in state and keep looking
q0 1 q1 1 right see a one, now we've seen odd number, keep looking
q0 B ha 0 same ran out after seeing even number
q1 0 q1 0 right see a zero, stay in state and keep looking
q1 1 q0 1 right see a one, now we've seen an even number, keep looking
q1 B hA 1 same ran out after seeing odd number
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.