// sub.tm // proper subtraction n-m represented 0^n 1 0^m // results in 0^(n-m) for n >= m // blank required at beginning and end start q0 limit 100 halt q6 // delta transitions p152 1) through 6) q0 #b q0 ## R q0 0 q1 #b R 1) q1 0 q1 0 R 2) q1 1 q2 1 R q2 1 q2 1 R 3) q2 0 q3 1 L q3 0 q3 0 L 4) q3 1 q3 1 L q3 #b q0 #b R q2 #b q4 #b L 5) q4 1 q4 #b L q4 0 q4 0 L q4 #b q6 0 R q0 1 q5 #b R 6) q5 0 q5 #b R q5 1 q5 #b R q5 #b q6 #b R q6 #b q6 // final state enddef tape #b00000100#b results in tape 000 i.e. 5-2=3 tape #b010#b zero result, blank tape tape #b0100#b bad, negative, zero blank tape tape #b000010#b result 000 tape #b00001000#b result 0