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
|
return current_state
|
||||||
|
|
||||||
if (current_state, EPS) in fsa_description_map:
|
if (current_state, EPS) in fsa_description_map:
|
||||||
next_states = fsa_description_map[(current_state, EPS)]
|
final_state = find_final_state(current_state, word, EPS)
|
||||||
for next_state in next_states:
|
if is_correct(final_state):
|
||||||
ending_state = traverse_states(next_state, word)
|
return final_state # found a correct state
|
||||||
if is_correct(ending_state):
|
|
||||||
return ending_state # found a correct state
|
|
||||||
|
|
||||||
for letter in word:
|
letter = word[0]
|
||||||
if (current_state, letter) not in fsa_description_map:
|
if (current_state, letter) not in fsa_description_map:
|
||||||
return "-1" # unspecified next state
|
return "-1" # unspecified next state
|
||||||
|
|
||||||
next_states = fsa_description_map[(current_state, letter)]
|
final_state = find_final_state(current_state, word, letter)
|
||||||
for next_state in next_states:
|
if is_correct(final_state):
|
||||||
ending_state = traverse_states(next_state, word[1:])
|
return final_state # found a correct state
|
||||||
if is_correct(ending_state):
|
|
||||||
return ending_state # found a correct state
|
|
||||||
return "-2" # no correct state found
|
return "-2" # no correct state found
|
||||||
|
|
||||||
return "-3" # fatal error
|
|
||||||
|
|
||||||
|
|
||||||
is_difference = []
|
is_difference = []
|
||||||
for i, word in enumerate(test_in):
|
for i, word in enumerate(test_in):
|
||||||
if i == 5:
|
|
||||||
print(word)
|
|
||||||
|
|
||||||
current_state = "0"
|
current_state = "0"
|
||||||
if len(word) != 0:
|
if len(word) != 0:
|
||||||
current_state = traverse_states(current_state, word)
|
current_state = traverse_states(current_state, word)
|
||||||
|
Loading…
Reference in New Issue
Block a user