C04 - code cleanup
This commit is contained in:
parent
2f2fb0d770
commit
398fa20843
@ -131,31 +131,22 @@ def traverse_states(current_state: str, word: str) -> str:
|
||||
return current_state
|
||||
|
||||
if (current_state, EPS) in fsa_description_map:
|
||||
next_states = fsa_description_map[(current_state, EPS)]
|
||||
for next_state in next_states:
|
||||
ending_state = traverse_states(next_state, word)
|
||||
if is_correct(ending_state):
|
||||
return ending_state # found a correct state
|
||||
final_state = find_final_state(current_state, word, EPS)
|
||||
if is_correct(final_state):
|
||||
return final_state # found a correct state
|
||||
|
||||
for letter in word:
|
||||
if (current_state, letter) not in fsa_description_map:
|
||||
return "-1" # unspecified next state
|
||||
letter = word[0]
|
||||
if (current_state, letter) not in fsa_description_map:
|
||||
return "-1" # unspecified next state
|
||||
|
||||
next_states = fsa_description_map[(current_state, letter)]
|
||||
for next_state in next_states:
|
||||
ending_state = traverse_states(next_state, word[1:])
|
||||
if is_correct(ending_state):
|
||||
return ending_state # found a correct state
|
||||
return "-2" # no correct state found
|
||||
|
||||
return "-3" # fatal error
|
||||
final_state = find_final_state(current_state, word, letter)
|
||||
if is_correct(final_state):
|
||||
return final_state # found a correct state
|
||||
return "-2" # no correct state found
|
||||
|
||||
|
||||
is_difference = []
|
||||
for i, word in enumerate(test_in):
|
||||
if i == 5:
|
||||
print(word)
|
||||
|
||||
current_state = "0"
|
||||
if len(word) != 0:
|
||||
current_state = traverse_states(current_state, word)
|
||||
|
Loading…
Reference in New Issue
Block a user