Skip to content

Instantly share code, notes, and snippets.

@mys721tx
Last active January 9, 2016 05:39
Show Gist options
  • Save mys721tx/a768042b8cb1b8748aa1 to your computer and use it in GitHub Desktop.
Save mys721tx/a768042b8cb1b8748aa1 to your computer and use it in GitHub Desktop.
3-State 2-Symbol Busy Beaver
"""
binary_adder.py: A binary adder implemented using SimpleTuringMachine
"""
import SimpleTuringMachine
ALPHABET = [0, 1]
STATES = ["HALT", "A", "B", "C"]
INITIAL_STATE = "A"
STATE_TABLE = {
(0, "A"): (1, False, "B"),
(0, "B"): (1, True, "A"),
(0, "C"): (1, True, "B"),
(1, "A"): (1, True, "C"),
(1, "B"): (1, False, "B"),
(1, "C"): (1, False, "HALT")
}
def main():
"""
the Turing machine
"""
machine = SimpleTuringMachine.Machine(
ALPHABET,
STATES,
INITIAL_STATE,
STATE_TABLE
)
while True:
print machine.get_tape()
print "State:", machine.get_state()
try:
machine.run()
except SimpleTuringMachine.HaltedError:
break
if __name__ == "__main__":
main()
@mys721tx
Copy link
Author

Using SimpleTuringMachine.

States and state table come from Wikipedia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment