Skip to content

Instantly share code, notes, and snippets.

@NonlinearFruit
Created September 28, 2018 15:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NonlinearFruit/6aabe8cd5e40bd3c5834e761ccad8fb3 to your computer and use it in GitHub Desktop.
Save NonlinearFruit/6aabe8cd5e40bd3c5834e761ccad8fb3 to your computer and use it in GitHub Desktop.
Turing Machine for adding two binary numbers. http://morphett.info/turing/turing.html
startIncrement _ * l find0
startIncrement * * r startIncrement
find0 1 0 l increment
find0 0 1 l endIncrement
find0 * * l find0
increment 1 0 l increment
increment * 1 * endIncrement
endIncrement _ * r finishIncrement
endIncrement * * l endIncrement
;-----------------------------------------
startDecrement _ * l find1
startDecrement * * r startDecrement
find1 1 * * decrement
find1 * * l find1
decrement 1 0 r decrement
decrement 0 1 r decrement
decrement _ * l endDecrement
endDecrement _ * r finishDecrement
endDecrement * * l endDecrement
;--------------------------------------------
startAdd * * * startDecrement
finishDecrement * * * nextWord
nextWord _ * r startIncrement
nextWord * * r nextWord
finishIncrement * * l jumpBack
jumpBack * * l isEmpty
isEmpty 0 * l isEmpty
isEmpty 1 * * beginning
isEmpty _ * r halt
beginning _ * r startAdd
beginning * * l beginning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment