Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. states = ['1', '2' ,'3', '4']
  2. final_states = ['3']
  3.  
  4. def run(string):
  5. next_state = '1'
  6. active_state = next_state
  7. for char in string:
  8.  
  9. if active_state == '1':
  10. if char == 'a':
  11. next_state = '2'
  12. if char == 'b':
  13. next_stat_index = '4'
  14.  
  15. if active_state == '2':
  16. if char == 'a':
  17. next_state = '4'
  18. if char == 'b':
  19. next_state = '3'
  20.  
  21. if active_state == '3':
  22. if char == 'b':
  23. next_state = '3'
  24. if char == 'a':
  25. next_state = '3'
  26. if active_state == '4':
  27. if char == 'a':
  28. next_state = '3'
  29. if char == 'b':
  30. next_state = '2'
  31.  
  32.  
  33. active_state = next_state
  34. return active_state in final_states
  35. if __name__ == '__main__':
  36. print(run('ab'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement