; Thomas Provan ; Write your Turing machine program here! ; Syntax: ; ';' starts a comment. ; '*' is a wildcard: it matches any symbol/state when used in the current symbol/state field; ; it means 'same as current' when used in new symbol/new state field. ; '_' represents the blank (space) symbol. ; Symbols must be a single non-whitespace character except ';'. ; States can be any word, not only numbers. ; ; L = {ww : w is in {0,1}*} ; I'm going to use two sets of characters ; {R,S} replaces {0,1} in the first w (w1) , {X,Y} replaces {0,1} in the second w (w2) ; Stage 0 : Labeling ; Label the two strings with different labels ; State 0 : Start state ; 'last' character of w1, replace and move right 0 0 R R 1 0 1 S R 1 ; Blank, Success, represents empty string, print 1 and done 0 _ 1 X halt ; {X,Y}, we're back here a second time. ; Replace this with {R,S}, then repeat 0 X R R 1 0 Y S R 1 ; State 1 : Assumption State ; Assume that the next {0,1} we see is in w2 1 0 X R 2 1 1 Y R 2 ; Back the second time. Ignore X&Y, loop 1 X X R 1 1 Y Y R 1 ; Blank. Failure. This means there is an odd number of characters, and we can automatically reject. 1 _ 0 L 10 ; Direct to 'failure' pattern, starting from the far left ; State 2 : Check State ; Looking for a blank. If we find one, we have finished labeling and can move to the next stage ; If we don't see a blank, we replace the {0,1} with {X,Y}, start moving back 2 0 X L 2 2 1 Y L 2 2 _ _ L 4 ; State 3: Backwards! ; Run backwards til you see {R,S} 2 Y Y L 2 2 X X L 2 2 R R R 0 2 S S R 0 ; Stage 1: Checking ; hmm..... ; When we finish labeling, we will be at the last character of w2 ; So, read that character, then pass through the rest of the {X,Y}, looking for the last {R,S} ; State 4: last unchecked char of w2 ; Read that character, move to appropriate check state 4 X _ L 5 4 Y _ L 6 ; See $, all chars consumed. Done 4 $ 1 L 10 ; State 5: R hunt ; The last character of w2 was X. Find the matching R at the end of w1 ; Found it, move back to the far right 5 R $ R 7 ; Found wrong symbol, direct to failure, starting in middle of string 5 S * R 8 ; Skip everything not {R,S} 5 * * L 5 State 6: S hunt ; Last character of w2 was X, find the matching S at the end of W1 ; Found it, move back to the far right 6 S $ R 7 ; Found wrong symbol, direct to failure, starting in middle of string 6 R * R 8 ; Skip everything not {R,S} 6 * * L 6 State 7: Backwards again 7 _ _ L 4 7 * * R 7 State 8: Failure Seq 8 _ 0 L 10 8 * * R 8 State 10: Erase 10 _ _ * halt 10 * _ L 10