# defines what a turing machine is from tmachine.VirtualHardware import VirtualHardware #creates virtual turing machine, including how long the tape of machine is turing_machine = VirtualHardware(tape_length=100) # asks for input state = raw_input("enter # ") #says input given will always be a number state = int(state) #converts integer given to binary number state = bin(state) #from second on, to remove 0,b from binary tape state = state[2:] #as long as there are still more digits in binary number... while state !="": print state # write binary number turing_machine.moveLeft()#move virtual tape left once(default is once, can be specified) turing_machine.write(state[0])#write first digit of binary code state = state[1:]#redueces state to what ever's left in binary code # show turing tape w turing_machine.tape()
""" This is an example using our turing machine class """ # Import our machine from tmachine.VirtualHardware import VirtualHardware # Initialize our turing machine turing_machine = VirtualHardware() # Write 10 1's to the tape for x in range(10): turing_machine.write(1) turing_machine.moveLeft() # print the tape for sanity tape = turing_machine.tape()