Правки по lab2

This commit is contained in:
2025-04-28 22:57:53 +03:00
parent 7030059bbb
commit 3963d304ec
7 changed files with 115 additions and 84 deletions

View File

@@ -2,20 +2,22 @@ from finite_automaton import FiniteAutomaton
def main():
alphabet = set("+-0123456789.,eE")
alphabet = set("+-0123456789.eE")
initial_state = "S0"
final_states = {"S2", "S4", "S7", "S8", "S9"}
final_states = {"S2", "S3", "S5", "S7", "S10"}
transitions = {
"S0": [("+-", "S1"), ("123456789", "S2"), ("0", "S8")],
"S1": [("123456789", "S2"), ("0", "S8")],
"S2": [("0123456789", "S2"), (".,", "S3"), ("eE", "S5")],
"S3": [("0123456789", "S4")],
"S4": [("0123456789", "S4"), ("eE", "S5")],
"S5": [("+-", "S6"), ("123456789", "S7"), ("0", "S9")],
"S6": [("123456789", "S7"), ("0", "S9")],
"S7": [("0123456789", "S7")],
"S8": [(".,", "S3")],
"S0": [("+-", "S1"), ("123456789", "S2"), ("0", "S3"), (".", "S6")],
"S1": [("123456789", "S2"), ("0", "S3"), (".", "S6")],
"S2": [("0123456789", "S2"), (".", "S5"), ("eE", "S8")],
"S3": [("0", "S3"), ("123456789", "S4"), (".", "S5"), ("eE", "S8")],
"S4": [("0123456789", "S4"), (".", "S5"), ("eE", "S8")],
"S5": [("0123456789", "S5"), ("eE", "S8")],
"S6": [("0123456789", "S7")],
"S7": [("0123456789", "S7"), ("eE", "S8")],
"S8": [("+-", "S9"), ("0123456789", "S10")],
"S9": [("0123456789", "S10")],
"S10": [("0123456789", "S10")],
}
automaton = FiniteAutomaton(
@@ -71,8 +73,9 @@ def main():
print(f"Ошибка: {e}")
continue
random_string = automaton.generate_random_string(stop_prob)
random_string, path = automaton.generate_random_string(stop_prob)
print(f"Сгенерированная строка: {random_string}")
print("Путь переходов:", " -> ".join(path))
else:
print(f"Неизвестная команда: {cmd}")