home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyth_os2.zip / python-1.0.2 / Demo / turing / sub.tm < prev    next >
Text File  |  1994-03-02  |  1KB  |  34 lines

  1. ;
  2. ; This turing machine subtracts two numbers; both numbers are given as
  3. ; a sequence of a's.
  4. ;
  5. ;
  6. ; The expected form is
  7. ;
  8. ;    n1,n2
  9. ;
  10. ; The result will be n1-n2, or zero if n1 < n2.
  11. ; The tape head will point to the result on return
  12. ;
  13.  
  14. <1, 'a'> --> <2, ' '>    ; subtract one initially
  15. <1, ','> --> <0, L>    ; n2 bigger than n1, point to empty string (' ')
  16.  
  17. <2, ' '> --> <2, R>    ; skip whitespace
  18. <2, 'a'> --> <2, R>    ; and the initial argument
  19. <2, ','> --> <3, R>    ; now we point to 2nd argument
  20.  
  21. <3, '#'> --> <3, R>    ; skip past old arguments
  22. <3, 'a'> --> <4, '#'>    ; decrement 2nd argument
  23. <3, ' '> --> <5, L>    ; end of input
  24.  
  25. <4, '#'> --> <4, L>    ; skip over the '#' characters
  26. <4, ','> --> <4, L>    ; and the delimiter
  27. <4, 'a'> --> <4, L>    ; and the 1st argument
  28. <4, ' '> --> <1, R>    ; point to first 'a' and change state
  29.  
  30. <5, '#'> --> <5, L>    ; skip over the '#' characters
  31. <5, ','> --> <5, L>    ; and the delimiter
  32. <5, 'a'> --> <5, L>    ; and the 1st argument
  33. <5, ' '> --> <0, 'a'>    ; insert the a that we initially removed
  34.