Example #1
0
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 10:37:20 2015

@author: Div 5 Cyberpatriot
"""
import sys
import os
sys.path.append("../")

from tmachine.VirtualHardware import VirtualHardware
tape = [None,1,1,None,1,1,1,1,1,1,1,None]
turing_machine = VirtualHardware(tape_length=50,init = tape)
running = True
state = 0
while running == True:
    print "state=",state
    print "tape position=",turing_machine.position()
    read_val = turing_machine.read()
    print "read_val=",read_val
    #print turing_machine.position()    
    if state == 0 :
        if read_val == None:
            turing_machine.write(None)
            turing_machine.moveLeft()
        elif read_val == 1:
            turing_machine.write("1")
            turing_machine.moveLeft()
            state = 1
    elif state == 1:
        if read_val == None:
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 18 10:28:35 2015

@author: Community Outreach
"""
import sys

sys.path.append("../")

from tmachine.VirtualHardware import VirtualHardware

tape = [None, 1, 1, None, 1, 1, 1, 1, 1, 1, 1, None]
turing_machine = VirtualHardware(tape_length=1000, init=tape)

running = True
state = 0
while running == True:
    read_val = turing_machine.read()
    print read_val
    print turing_machine.position()
    if state == 0:
        if read_val == None:
            turing_machine.write(None)
            turing_machine.moveLeft()
            print "nothing"
        elif read_val == 1:
            turing_machine.write(1)
            turing_machine.moveLeft()
            print "1"
            state = 1
Example #3
0
import pprint
filename = "unary addition.turing.py"
statedict = {}


f = open(filename)

import pprint 
import sys
import os
sys.path.append("../")

from tmachine.VirtualHardware import VirtualHardware
tape = ["_","1","1","_","1","1","1","1","1","1","1","_"]
turing_machine = VirtualHardware(tape_length=50, init = tape)
running = True
state = 0
#Read in the file 



for line in f:
    value = line.strip()
    valuelist = value.split()
    if len(valuelist) != 5:
        print "can't use line, ERROR!"
        print len(valuelist)
        continue 
    
    
Example #4
0
#!/usr/bin/python
"""
Inputs a number from the user, and prints it to the turing machine using only turing 
state transition rules. 
"""
__author__ = "Kyania Burke and Trevon Bennett"

#  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()