//this program should recognise strings in 0^n 1^n 0^n //that is, "count thrice" //B is "blank" //f is final (accepting) state //q0 read leftmost 0, replace with X. can't see 1 here 0 0 1 X R //replace leftmost 0 with X, start to look for 1s 0 B f B L //accept empty string (n=0) 0 X 0 X R //skip over initial Xs if any //q1 read a 1, replace with X. can't see B here 1 0 1 0 R //skiping over left 0s 1 1 2 X R //replace leftmost 1 with X start looking for a 0 1 X 1 X R //skipping over Xs //q2 saw that 1, now want a 0. can't see B here 2 0 3 X R //found that 0, replaced with X 2 1 2 1 R //skipping over more 1s 2 X 2 X R //skipping over Xs //q3 repaced a 0 a 1 and a 0 with Xs, go to Right end. Can't see an X here 3 0 3 0 R 3 1 3 1 R 3 B 4 B L //found end of input, go left to see if done //q4 if all Xs, done. any 0 or 1 and we'll move left to restart 4 0 5 0 L //0 is not X, more to do 4 1 5 1 L //1 is not X, more to do 4 B f B L //have moved over tape, all Xs. ACCEPT 4 X 4 X L //X is X, keep moving Left //q5 moveing to left B to restart. Skip over everything else 5 0 5 0 L 5 1 5 1 L 5 B 0 B R //got to the left, start moving R to count again 5 X 5 X L