Compare commits

...

8 Commits

Author SHA1 Message Date
Pawel Felcyn
060ba0d890 add helpers 2023-11-13 15:02:07 +01:00
Pawel Felcyn
d04a124987 fix b06 2023-11-13 15:00:14 +01:00
Pawel Felcyn
ad9e565a23 b09 2023-11-13 14:57:17 +01:00
Pawel Felcyn
0b4741a48c b08 2023-11-13 14:52:51 +01:00
Pawel Felcyn
e1e1346813 fix b07 2023-11-13 14:50:07 +01:00
Pawel Felcyn
4f60436fc0 b07 2023-11-13 14:39:16 +01:00
Pawel Felcyn
3e1db9e80c b06 2023-11-13 14:24:03 +01:00
Pawel Felcyn
f57b8ff2b6 b05 2023-11-13 14:06:11 +01:00
11 changed files with 1023 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: ')

190
TaskB06/fsa_description.arg Normal file
View File

@ -0,0 +1,190 @@
0 0 a
1 2 a
2 0 a
3 0 a
4 0 a
5 0 a
6 6 a
0 0 b
1 0 b
2 0 b
3 0 b
4 0 b
5 0 b
6 6 b
0 0 c
1 0 c
2 0 c
3 0 c
4 0 c
5 0 c
6 6 c
0 0 d
1 0 d
2 0 d
3 0 d
4 0 d
5 0 d
6 6 d
0 0 e
1 0 e
2 0 e
3 0 e
4 5 e
5 0 e
6 6 e
0 0 f
1 0 f
2 0 f
3 0 f
4 0 f
5 0 f
6 6 f
0 0 g
1 0 g
2 0 g
3 0 g
4 0 g
5 0 g
6 6 g
0 1 h
1 0 h
2 0 h
3 0 h
4 0 h
5 0 h
6 6 h
0 0 i
1 0 i
2 0 i
3 0 i
4 0 i
5 0 i
6 6 i
0 0 j
1 0 j
2 0 j
3 0 j
4 0 j
5 0 j
6 6 j
0 0 k
1 0 k
2 0 k
3 0 k
4 0 k
5 0 k
6 6 k
0 0 l
1 0 l
2 0 l
3 4 l
4 0 l
5 0 l
6 6 l
0 0 m
1 0 m
2 3 m
3 0 m
4 0 m
5 0 m
6 6 m
0 0 n
1 0 n
2 0 n
3 0 n
4 0 n
5 0 n
6 6 n
0 0 o
1 0 o
2 0 o
3 0 o
4 0 o
5 0 o
6 6 o
0 0 p
1 0 p
2 0 p
3 0 p
4 0 p
5 0 p
6 6 p
0 0 q
1 0 q
2 0 q
3 0 q
4 0 q
5 0 q
6 6 q
0 0 r
1 0 r
2 0 r
3 0 r
4 0 r
5 0 r
6 6 r
0 0 s
1 0 s
2 0 s
3 0 s
4 0 s
5 0 s
6 6 s
0 0 t
1 0 t
2 0 t
3 0 t
4 0 t
5 6 t
6 6 t
0 0 u
1 0 u
2 0 u
3 0 u
4 0 u
5 0 u
6 6 u
0 0 v
1 0 v
2 0 v
3 0 v
4 0 v
5 0 v
6 6 v
0 0 w
1 0 w
2 0 w
3 0 w
4 0 w
5 0 w
6 6 w
0 0 x
1 0 x
2 0 x
3 0 x
4 0 x
5 0 x
6 6 x
0 0 y
1 0 y
2 0 y
3 0 y
4 0 y
5 0 y
6 6 y
0 0 z
1 0 z
2 0 z
3 0 z
4 0 z
5 0 z
6 6 z
0 0
1 0
2 0
3 0
4 0
5 0
6 6
6

29
TaskB06/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='\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)
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: ')

217
TaskB07/fsa_description.arg Normal file
View File

@ -0,0 +1,217 @@
0 0 a
1 0 a
2 0 a
3 0 a
4 0 a
5 0 a
6 7 a
7 7 a
0 0 b
1 0 b
2 0 b
3 0 b
4 0 b
5 0 b
6 0 b
7 7 b
0 0 c
1 0 c
2 0 c
3 0 c
4 0 c
5 0 c
6 0 c
7 7 c
0 0 d
1 0 d
2 0 d
3 0 d
4 0 d
5 0 d
6 0 d
7 7 d
0 0 e
1 0 e
2 0 e
3 4 e
4 0 e
5 0 e
6 0 e
7 7 e
0 0 f
1 0 f
2 0 f
3 0 f
4 0 f
5 0 f
6 0 f
7 7 f
0 0 g
1 0 g
2 0 g
3 0 g
4 0 g
5 0 g
6 0 g
7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.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)
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: ')

190
TaskB08/fsa_description.arg Normal file
View File

@ -0,0 +1,190 @@
0 0 a
1 0 a
2 0 a
3 0 a
4 0 a
5 0 a
6 6 a
0 0 b
1 0 b
2 0 b
3 0 b
4 0 b
5 0 b
6 6 b
0 0 c
1 0 c
2 0 c
3 0 c
4 0 c
5 0 c
6 6 c
0 0 d
1 0 d
2 0 d
3 0 d
4 0 d
5 0 d
6 6 d
0 0 e
1 0 e
2 0 e
3 0 e
4 5 e
5 0 e
6 6 e
0 0 f
1 0 f
2 0 f
3 0 f
4 0 f
5 0 f
6 6 f
0 0 g
1 0 g
2 0 g
3 0 g
4 0 g
5 0 g
6 6 g
0 0 h
1 0 h
2 0 h
3 0 h
4 0 h
5 0 h
6 6 h
0 0 i
1 0 i
2 0 i
3 4 i
4 0 i
5 0 i
6 6 i
0 1 j
1 0 j
2 0 j
3 0 j
4 0 j
5 0 j
6 6 j
0 0 k
1 0 k
2 0 k
3 0 k
4 0 k
5 0 k
6 6 k
0 0 l
1 0 l
2 3 l
3 0 l
4 0 l
5 0 l
6 6 l
0 0 m
1 0 m
2 0 m
3 0 m
4 0 m
5 0 m
6 6 m
0 0 n
1 0 n
2 0 n
3 0 n
4 0 n
5 0 n
6 6 n
0 0 o
1 0 o
2 0 o
3 0 o
4 0 o
5 0 o
6 6 o
0 0 p
1 0 p
2 0 p
3 0 p
4 0 p
5 0 p
6 6 p
0 0 q
1 0 q
2 0 q
3 0 q
4 0 q
5 0 q
6 6 q
0 0 r
1 0 r
2 0 r
3 0 r
4 0 r
5 0 r
6 6 r
0 0 s
1 0 s
2 0 s
3 0 s
4 0 s
5 0 s
6 6 s
0 0 t
1 0 t
2 0 t
3 0 t
4 0 t
5 6 t
6 6 t
0 0 u
1 2 u
2 0 u
3 0 u
4 0 u
5 0 u
6 6 u
0 0 v
1 0 v
2 0 v
3 0 v
4 0 v
5 0 v
6 6 v
0 0 w
1 0 w
2 0 w
3 0 w
4 0 w
5 0 w
6 6 w
0 0 x
1 0 x
2 0 x
3 0 x
4 0 x
5 0 x
6 6 x
0 0 y
1 0 y
2 0 y
3 0 y
4 0 y
5 0 y
6 6 y
0 0 z
1 0 z
2 0 z
3 0 z
4 0 z
5 0 z
6 6 z
0 0
1 0
2 0
3 0
4 0
5 0
6 6
6

29
TaskB08/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='\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)
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: ')

217
TaskB09/fsa_description.arg Normal file
View File

@ -0,0 +1,217 @@
0 0 a
1 2 a
2 0 a
3 0 a
4 0 a
5 0 a
6 0 a
7 7 a
0 0 b
1 0 b
2 0 b
3 4 b
4 0 b
5 0 b
6 0 b
7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
2 0 x
3 0 x
4 0 x
5 0 x
6 0 x
7 7 x
0 0 y
1 0 y
2 0 y
3 0 y
4 0 y
5 0 y
6 0 y
7 7 y
0 0 z
1 0 z
2 0 z
3 0 z
4 0 z
5 0 z
6 0 z
7 7 z
0 0
1 0
2 0
3 0
4 0
5 0
6 0
7 7
7

29
TaskB09/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='\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)
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: ')

View File

@ -0,0 +1,8 @@
import os
alphabet = 'abcdefghijklmnopqrstuvwxyz '
with open(os.path.join(os.path.dirname(__file__), 'fsa_description.arg'), 'w') as file:
for c in alphabet:
for i in range(0, 6):
file.write(f'{i}\t0\t{c}\n')
file.write(f'6\t6\t{c}\n')
file.write('6')