This commit is contained in:
Pawel Felcyn 2023-11-13 14:06:11 +01:00
parent 58a11535df
commit f57b8ff2b6
2 changed files with 85 additions and 0 deletions

View File

@ -0,0 +1,56 @@
0 1 1
1 2 9
2 3 0
2 3 1
2 3 2
2 3 3
2 3 4
2 3 5
2 3 6
2 3 7
2 3 8
2 3 9
3 4 0
3 4 1
3 4 2
3 4 3
3 4 4
3 4 5
3 4 6
3 4 7
3 4 8
3 4 9
4 4 0
4 4 1
4 4 2
4 4 3
4 4 4
4 4 5
4 4 6
4 4 7
4 4 8
4 4 9
4 4 x
0 0 x
0 0 0
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
1 0 x
1 0 0
1 0 1
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
2 0 x
3 0 x
4

29
TaskB05/run.py Normal file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
import pandas as pd
import os
def automat_fun(recursive_df: pd.DataFrame):
first_row = recursive_df.iloc[0]
recursive_df = recursive_df.iloc[1:,:]
return lambda char, state: first_row[1] if state == first_row[0] and char == first_row[2] else automat_fun(recursive_df)(char, state)
def create_automat_from_file(file_path: str):
df = pd.read_csv(file_path, sep=' ', header=None)
accept_state = df.tail(1).iloc[0, 0]
df = df.iloc[:-1,:]
return accept_state, automat_fun(df)
file_path = os.path.join(os.path.dirname(__file__), 'fsa_description.arg')
accept_state, automat_function = create_automat_from_file(file_path)
txt = input('Write valid input: ')
while txt != 'exit':
state = 0
for c in txt:
if (c == '\n'):
break
state = automat_function(c, state)
print('YES' if state == accept_state else "NO")
txt = input('Write valid input: ')