Advertisement
milanmetal

Turing Machine / Shift bit-string to the right

Oct 29th, 2018
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.26 KB | None | 0 0
  1. // Input: a binary number n, for example 1101
  2. // Ouput: 01101
  3. //
  4. // Author: Milan Nedic
  5. //
  6.  
  7. name: Shift bit-string to the right
  8. init: to_the_right
  9. accept: qAccept
  10.  
  11. to_the_right,0
  12. to_the_right,0,>
  13.  
  14. to_the_right,1
  15. to_the_right,1,>
  16.  
  17. // to_the_right takes me to the first empty position on the right
  18.  
  19. to_the_right, _                 // empty found? put the placeholder
  20. blank_found, x, <               // and get back one place
  21.  
  22. blank_found, x                  // you are on placeholder?
  23. to_the_left, x, <               // move back one place
  24.  
  25. to_the_left, x                  // move back through all placeholders
  26. to_the_left, x, <
  27.  
  28. to_the_left, 0                  // you saw 0 while moving back?
  29. bring_0, 0, >                   // bring it forward one place
  30.  
  31. bring_0, 0
  32. bring_0, x, >
  33.  
  34. bring_0, x
  35. to_the_left, 0, <
  36.  
  37. // ---------------------
  38. to_the_left, 1                  // you saw 1 while moving back?
  39. bring_1, 1, >                   // bring it forward one place
  40.  
  41. bring_1, 1
  42. bring_1, x, >
  43.  
  44. bring_1, x
  45. to_the_left, 1, <
  46.  
  47. to_the_left, _                  // blank on the way to the left?
  48. clean_placeholder,_ , >         // keep it blank and move right
  49.  
  50. clean_placeholder, _            // clean_placeholder initiated
  51. to_the_right, _, >              // keep blank and move right
  52.  
  53. to_the_right, x                 // found placeholder?
  54. qAccept, 0, -                   // complete algorithm
  55.  
  56. //to_the_right,_
  57. //qAccept,_,-
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement