Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import queue
- def Non_deterministic(poc_stanje,program):
- q=queue.Queue()
- q.push({poc_stanje[0],poc_stanje[1],poc_stanje[2]})
- info=[]
- while q.Empty()!=0:
- izasao=False
- elem=q.get()
- head=elem[2]
- state=elem[1]
- tape=elem[0]
- try:
- current=program[state][tape[head]]
- except:
- print("Pogresan simbol")
- exit(1)
- while(len(current)==1):
- state=current[0][0]
- if(state=="q+"):
- return current[0]
- if(state=="q-"):
- info.append(current)
- izasao=True
- break
- tape[head]=current[0][1]
- if(current[0][2]=="r"):
- head+=1
- else: head-=1
- if(head<0 or head>=len(tape)):
- info.append(current)
- izasao=True
- break
- if(not izasao):
- for i in current:
- state=current[i][0]
- if(state=="q+"):
- return current[0]
- if(state=="q-"):
- info.append(current)
- continue
- new_tape=tape.list()
- new_tape[head]=current[i][1]
- if(current[0][2]=="r"):
- new_head=head+1
- else: new_head=head-1
- if(head<0 or head>=len(tape)):
- info.append(current)
- else:q.push({new_tape,state,new_head})
- return info
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement