Compare commits
5 Commits
96a028393c
...
58a11535df
Author | SHA1 | Date | |
---|---|---|---|
![]() |
58a11535df | ||
![]() |
17e95848f6 | ||
![]() |
5c03c766de | ||
![]() |
e1e0578083 | ||
![]() |
a09908bb53 |
@ -5,4 +5,4 @@ Read strings from the standard input.
|
||||
If a string is accepted by the
|
||||
automaton, write YES, otherwise- write NO.
|
||||
|
||||
The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out
|
||||
The program is invoked like this: ./run.py fsa_description.arg < test1.in > test1.out
|
36
TaskB00/run.py
Normal file
36
TaskB00/run.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import pandas as pd
|
||||
import os
|
||||
import sys
|
||||
|
||||
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='\t', 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)
|
||||
|
||||
input_file_path = os.path.join(os.path.dirname(__file__), 'test1.in')
|
||||
output_file_path = os.path.join(os.path.dirname(__file__), 'test1.out')
|
||||
results: list[str] = []
|
||||
|
||||
with open(input_file_path, 'r', encoding='utf8') as input_file:
|
||||
for line in input_file:
|
||||
state = 0
|
||||
for c in line:
|
||||
if c == '\n':
|
||||
continue
|
||||
state = automat_function(c, state)
|
||||
results.append('YES\n' if state == accept_state else 'NO\n')
|
||||
|
||||
|
||||
with open(output_file_path, 'w') as output_file:
|
||||
output_file.writelines(results)
|
9
TaskB00/test1.out
Normal file
9
TaskB00/test1.out
Normal file
@ -0,0 +1,9 @@
|
||||
NO
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
||||
NO
|
11
TaskB01/fsa_description.arg
Normal file
11
TaskB01/fsa_description.arg
Normal file
@ -0,0 +1,11 @@
|
||||
0 4 1
|
||||
4 4 0
|
||||
4 4 1
|
||||
0 1 0
|
||||
1 4 0
|
||||
1 2 1
|
||||
2 3 0
|
||||
2 3 1
|
||||
3 3 0
|
||||
3 2 1
|
||||
2
|
29
TaskB01/run.py
Normal file
29
TaskB01/run.py
Normal 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 binary sequence: ')
|
||||
|
||||
while txt != 'exit':
|
||||
state = 0
|
||||
for c in txt:
|
||||
if (c == '\n'):
|
||||
break
|
||||
state = automat_function(int(c), state)
|
||||
print('YES' if state == accept_state else "NO")
|
||||
txt = input('Write binary sequence: ')
|
11
TaskB02/fsa_description.arg
Normal file
11
TaskB02/fsa_description.arg
Normal file
@ -0,0 +1,11 @@
|
||||
0 4 0
|
||||
4 4 1
|
||||
4 4 0
|
||||
0 1 1
|
||||
1 4 1
|
||||
1 2 0
|
||||
2 3 1
|
||||
2 3 0
|
||||
3 3 1
|
||||
3 2 0
|
||||
2
|
29
TaskB02/run.py
Normal file
29
TaskB02/run.py
Normal 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 binary sequence: ')
|
||||
|
||||
while txt != 'exit':
|
||||
state = 0
|
||||
for c in txt:
|
||||
if (c == '\n'):
|
||||
break
|
||||
state = automat_function(int(c), state)
|
||||
print('YES' if state == accept_state else "NO")
|
||||
txt = input('Write binary sequence: ')
|
5
TaskB03/fsa_description.arg
Normal file
5
TaskB03/fsa_description.arg
Normal file
@ -0,0 +1,5 @@
|
||||
0 1 0
|
||||
1 0 0
|
||||
0 0 1
|
||||
1 1 1
|
||||
0
|
29
TaskB03/run.py
Normal file
29
TaskB03/run.py
Normal 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 binary sequence: ')
|
||||
|
||||
while txt != 'exit':
|
||||
state = 0
|
||||
for c in txt:
|
||||
if (c == '\n'):
|
||||
break
|
||||
state = automat_function(int(c), state)
|
||||
print('YES' if state == accept_state else "NO")
|
||||
txt = input('Write binary sequence: ')
|
5
TaskB04/fsa_description.arg
Normal file
5
TaskB04/fsa_description.arg
Normal file
@ -0,0 +1,5 @@
|
||||
0 1 0
|
||||
1 0 0
|
||||
0 0 1
|
||||
1 1 1
|
||||
1
|
29
TaskB04/run.py
Normal file
29
TaskB04/run.py
Normal 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 binary sequence: ')
|
||||
|
||||
while txt != 'exit':
|
||||
state = 0
|
||||
for c in txt:
|
||||
if (c == '\n'):
|
||||
break
|
||||
state = automat_function(int(c), state)
|
||||
print('YES' if state == accept_state else "NO")
|
||||
txt = input('Write binary sequence: ')
|
Loading…
Reference in New Issue
Block a user