Last active
January 9, 2016 05:39
-
-
Save mys721tx/a768042b8cb1b8748aa1 to your computer and use it in GitHub Desktop.
3-State 2-Symbol Busy Beaver
This file contains 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
""" | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using SimpleTuringMachine.
States and state table come from Wikipedia.