Created
January 10, 2019 22:33
-
-
Save bergwerf/86a1edcd794eed623f3b75bc0786ccfc to your computer and use it in GitHub Desktop.
DTm counter (http://morphett.info/turing/turing.html)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; This program counts the number of a characters in a string | |
| ; and appends it in reverse binary to the end of the tape | |
| ; Go to nil state | |
| 0 * * * nil | |
| ; Counting program | |
| nil a x r odd | |
| even a x r odd | |
| odd a a r even | |
| nil * * r nil | |
| odd * * r odd | |
| even * * r even | |
| ; Put down 0 at the end of the tape if the number | |
| ; of a characters is even. This is the case if we | |
| ; are in the even state. | |
| even _ 0 * return | |
| odd _ 1 * return | |
| nil _ # * halt | |
| ; Return to tape start | |
| return _ _ r nil | |
| return * * l return |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment