Правки по lab2
This commit is contained in:
@@ -27,25 +27,28 @@ class FiniteAutomaton:
|
||||
|
||||
for char in input_string:
|
||||
if char not in self.alphabet:
|
||||
return f"Символ '{char}' не из алфавита", transitions_path
|
||||
return f"Символ '{char}' не из алфавита ✗", transitions_path
|
||||
|
||||
next_state = self._get_next_state(current_state, char)
|
||||
|
||||
if next_state is None:
|
||||
return "Строка не соответствует", transitions_path
|
||||
return "Строка не соответствует ✗", transitions_path
|
||||
|
||||
transitions_path.append(next_state)
|
||||
current_state = next_state
|
||||
|
||||
return (
|
||||
"Строка соответствует"
|
||||
"Строка соответствует ✓"
|
||||
if current_state in self.final_states
|
||||
else "Строка не соответствует"
|
||||
else "Строка не соответствует ✗"
|
||||
), transitions_path
|
||||
|
||||
def generate_random_string(self, stop_probability: float = 0.3) -> str:
|
||||
def generate_random_string(
|
||||
self, stop_probability: float = 0.3
|
||||
) -> tuple[str, list[str]]:
|
||||
result = []
|
||||
current_state = self.initial_state
|
||||
path = [current_state]
|
||||
|
||||
while True:
|
||||
if (
|
||||
@@ -59,5 +62,6 @@ class FiniteAutomaton:
|
||||
char = random.choice(transition)
|
||||
result.append(char)
|
||||
current_state = next_state
|
||||
path.append(current_state)
|
||||
|
||||
return "".join(result)
|
||||
return "".join(result), path
|
||||
|
||||
Reference in New Issue
Block a user