简体   繁体   中英

How to build special turing machine

Good day. I have a question. Many people are familiar with the Turing machine. The following task arose, which I can't solve for a long time: there is an alphabet consisting of the letters "X", "Y" "Z", if the number of letters "Z" in the word is exactly 2 more than the letters "X", replace the second letter "Z" with "X". Otherwise, leave the word unchanged. Considering that I cannot change the original word and the tape is infinite (that is, I cannot write an infinite number of states for the machine), I do not understand how to do this.

Just to make it more clear, if the input is for example:

XXXYZZZZZ

then the output you need is:

XXXYZXZZZZ

And if the input is:

XXYZZ

Then everything needs to stay the same, since (number of Z's) - (number of X's) != 2

XXYZZ

If I understood the problem correctly, in the way I defined above, then here comes the solution with Morphett's TM Simulator, with $ sign as left-end marker:

1 $ $ r 1
1 X A r 2
1 Y Y r 4

2 X X r 2
2 B B r 2
2 Y Y r 2
2 Z B R 3

3 Y Y l 3
3 B B l 3
3 X X l 3
3 A A r 1
3 Z Z l 3

4 Y Y r 4
4 B B r 4
4 Z B r 5
4 _ _ l 7

5 Z B r 6
5 _ _ l 7

6 Z Z l 7
6 _ _ l 8

7 B Z l 7
7 Y Y l 7
7 A X l 7
7 $ $ r 12 

8 B Z l 8
8 Y Y l 8
8 A X l 8
8 $ $ r 9

9 X X r 9
9 Y Y r 9
9 Z Z r 10

10 Z X r 11

11 Z Z r 11
11 _ _ l halt

12 X X r 12
12 Y Y r 12
12 Z Z r 12
12 _ _ l halt

Copy this code and then paste it to http://morphett.info/turing/turing.html

From advanced options, set initial state to 1 from 0.

Do not forget to add a "$" to beginning of every input.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM