Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. import queue
  2. def Non_deterministic(poc_stanje,program):
  3. q=queue.Queue()
  4. q.push({poc_stanje[0],poc_stanje[1],poc_stanje[2]})
  5. info=[]
  6. while q.Empty()!=0:
  7. izasao=False
  8. elem=q.get()
  9. head=elem[2]
  10. state=elem[1]
  11. tape=elem[0]
  12. try:
  13. current=program[state][tape[head]]
  14. except:
  15. print("Pogresan simbol")
  16. exit(1)
  17. while(len(current)==1):
  18. state=current[0][0]
  19. if(state=="q+"):
  20. return current[0]
  21. if(state=="q-"):
  22. info.append(current)
  23. izasao=True
  24. break
  25. tape[head]=current[0][1]
  26. if(current[0][2]=="r"):
  27. head+=1
  28. else: head-=1
  29. if(head<0 or head>=len(tape)):
  30. info.append(current)
  31. izasao=True
  32. break
  33.  
  34. if(not izasao):
  35. for i in current:
  36. state=current[i][0]
  37. if(state=="q+"):
  38. return current[0]
  39. if(state=="q-"):
  40. info.append(current)
  41. continue
  42. new_tape=tape.list()
  43. new_tape[head]=current[i][1]
  44. if(current[0][2]=="r"):
  45. new_head=head+1
  46. else: new_head=head-1
  47. if(head<0 or head>=len(tape)):
  48. info.append(current)
  49. else:q.push({new_tape,state,new_head})
  50.  
  51. return info
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement