在我自己的圖靈僞代碼:
- 拷貝輸入A0B到磁帶2
- 寫000010000到磁帶3
- 由A從磁帶2乘上帶3的數量由
- 從A開始處開始
- 將0寫入磁帶4
- 拷貝次數3 => 4
- 向前移動一次在磁帶3(3 ++)
- 去到步驟3,除非A結束
- 從磁帶4移動答案帶3
- 減量磁帶上數B 2
- 如果B於磁帶2不爲0時,轉到步驟2
- 答案複製從磁帶3到磁帶1
這裏是圖靈代碼應該工作(磁帶像指針,小寫字母,輸入帶i
):
# At the start for 2^3
# i: 000111011110000
# ^
_start_ -> *a = 0, start2
start2 [*i==0] -> i++, *a++ = 0, *b++ = 0, start4
start2 [*i==1] -> i++, *a++ = 1, start2
start4 [*i==0] -> *b-- = 0, b--, initc
start4 [*i==1] -> i++, *b++ = 1, start4
initc -> *c++ = 0, *c++ = 1, *c++ = 1, *c-- = 0, mult
# example
# i: 00011101111000
# ^
# a: 001110000
# ^
# b: 001111000
# ^
# c: 00011000
# ^
mult[*b==0]: lastcpy
mult[*b==1]: b--, *d++ = 0, *d++ = 1, rewa
rewa[*a==0]: a++, a++, multcpy
rewa[*a==1]: a--, rewa
multcpy[*c==1]: c++, multcpy2
multcpy[*c==0]: multcpy3
multcpy2[*a==0]: multcpy
multcpy2[*a==1]: *d++ = 1, multcpy2
multcpy3: *d-- = 0, *c = 0, cpydtoc
cpydtoc[*d==1]: d--, *c++ = 1, cpydtoc
cpydtoc[*d==0]: *c-- = 0, mult
lastcpy[*c==1]: *i++ = 1, c--, lastcpy
lastcpy[*c==0]: *i = 0, _finish_
# Should end with
# i: 00011101111011111111100
# ^
請檢查錯誤:)
你有一個很好的圖靈機,我可以檢查我的代碼? – 2009-06-23 02:34:51
不,對不起。我只是在jflap上工作。 – andandandand 2009-06-23 03:02:09