; Jiannan C ; # of Rules: 27 ; TM machine decides the language ; L = {x#y : x, y ? {0, 1}+ and ; x and y are equal-length strings ; that differ on a single char} ; ; The input alphabet is {0,1,#} ; The tape alphabet is {0,1,#,a,b,$,!,_} ; ; ; ZERO (START STATE) ; ; we replace all (0,1) to (a,b) before #, ; for the convenience of jumping between x string and y string. ; Then we go to [toRead]. ; 0 0 a R 0 ;01: replace 0 to a in x 0 1 b R 0 ;02: replace 1 to b in x 0 # * * [toRead] ;03 0 * * L [toReject] ;04, find end_ or illegal char ; L for escaping end_ ; ; TO_READ ; ; prepare to read again, ; scroll to the left-most char. ; ; WARNING: [toRead] cannot be called at the location of end_ ; [toRead] * * L [toRead] ;05: scroll to the left-most char [toRead] _ * R [read] ;06 ; ; READ ; ; read the left-most char of x, read x[left] ; In this process, we also erase from left to right. ; Then we go to [compare0], [compare1] or [check!]. ; ; WARNING: [read] can only be called at the locations of a,b,# ; [read] a _ R [compare0] ;07: read x[left] == a [read] b _ R [compare1] ;08: read x[left] == b [read] # _ R [check!] ;09: read x[left] == # ; ; COMPARE ; ; after reading the left-most char of x, ; we should compare it with the left-most char of y. ; ; if(x[left]== a) ; if(y[left]==0) ; y[left] = $; //same original chars ; if(y[left]==1) ; y[left] = !; //different original chars ; if(y[left]==_) ; toReject(); //x is longer than y ; ; if(x[left]== b) ; if(y[left]==0) ; y[left] = !; //different original chars ; if(y[left]==1) ; y[left] = $; //same original charas ; if(y[left]==_) ; toReject(); //x is longer than y ; ; if(x[left]==#) ; check!(); ; [compare0] * * R [compare0] ;10: skip to y[left] [compare0] 0 $ * [toRead] ;11: chars are same [compare0] 1 ! * [toRead] ;12: chars are different [compare0] _ * L [toReject] ;13: x is longer than y [compare1] * * R [compare1] ;14: skip to y[left] [compare1] 0 ! * [toRead] ;15: chars are different [compare1] 1 $ * [toRead] ;16: chars are same [compare1] _ * L [toReject] ;17: x is longer than y ; ; CHECK! (CHECK BEFORE !) ; ; After finishing comparison, we should check ! for the # of different chars. ; from left to right, we skip $, find a !, then go to [!check]. ; In this process, we also erase from left to right. ; ; If we find other chars (_,0,1,#), we should go to [reject], because: ; _ means we cannot find a ! ; 0 means y is longer than x ; 1 means y is longer than x ; # means we have two # in the original string ; ; WARNING: [check!] cannot be called at the location of begin_ ; [check!] $ _ R [check!] ;18: skip $ [check!] ! _ R [!check] ;19: find ! [check!] * * * [reject] ;20: find _,0,1,# ; ; !CHECK (CHECK AFTER !) ; ; after we find a !, we should check the second ! ; from left to right, we skip $, find a _, then we accept it. ; If we find a second !, we’ll reject it. ; In this process, we also erase from left to right. ; ; If we find other chars (!,0,1,#), we should go to [reject], because: ; ! means we find two ! ; 0 means y is longer than x ; 1 means y is longer than x ; # means we have two # in the original string ; [!check] $ _ R [!check] ;21: skip $ [!check] _ 1 * halt ;22: find _, accept it, [SUCCESS] [!check] * * * [reject] ;23: find !,0,1,# ; ; TO_REJECT ; ; prepare to reject, ; scroll to the left-most char ; ; WARNING: [toReject] cannot be called at the location of end_ ; [toReject] * * L [toReject] ;24: scroll to the left-most char [toReject] _ * R [reject] ;25 ; ; REJECT ; ; erase from left-most char to right-most char, ; then print the reject-char 0 ; ; WARNING: [reject] cannot be called at the location of begin_ ; [reject] * _ R [reject] ;26: erase from left to right [reject] _ 0 * halt ;27: reject it, [FAIL]