Skip to content

Instantly share code, notes, and snippets.

@SED4906
Created April 20, 2019 14:29
Show Gist options
  • Save SED4906/74075683e2926e4d0bd968344752f3eb to your computer and use it in GitHub Desktop.
Save SED4906/74075683e2926e4d0bd968344752f3eb to your computer and use it in GitHub Desktop.
turingmachine.io
# Adds two binary numbers.
input: '0111 1100'
blank: ' '
start state: end
table:
# scan to the right
end:
[1,0]: R
' ' : {R: right}
# scan to the rightmost digit
right:
[1,0]: R
' ' : {L: borrow}
# then borrow the 1
borrow:
1 : {write: 0, L: left}
0 : {write: 1, L}
' ' : {write: ' ', L: done}
# scan to the left
left:
[1,0] : L
' ' : {L: carry}
# then carry the 1
carry:
1 : {write: 0, L}
0 : {write: 1, R: end}
' ' : {R: end}
done:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment