Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- states = ['1', '2' ,'3', '4']
- final_states = ['3']
- def run(string):
- next_state = '1'
- active_state = next_state
- for char in string:
- if active_state == '1':
- if char == 'a':
- next_state = '2'
- if char == 'b':
- next_stat_index = '4'
- if active_state == '2':
- if char == 'a':
- next_state = '4'
- if char == 'b':
- next_state = '3'
- if active_state == '3':
- if char == 'b':
- next_state = '3'
- if char == 'a':
- next_state = '3'
- if active_state == '4':
- if char == 'a':
- next_state = '3'
- if char == 'b':
- next_state = '2'
- active_state = next_state
- return active_state in final_states
- if __name__ == '__main__':
- print(run('ab'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement