Compare commits

...

28 Commits

Author SHA1 Message Date
Veronika Polevara 60e00a1366 Merge branch 'master' into TasksB 2023-12-10 22:07:35 +01:00
Veronika Polevara af19e6039d Delete 'TaskD04/simple.out' 2023-12-10 22:06:08 +01:00
Veronika Polevara 7aa19cf544 Delete 'TaskD04/simple.in' 2023-12-10 22:06:05 +01:00
Veronika Polevara cba04c64cb Delete 'TaskD04/simple.exp' 2023-12-10 22:06:01 +01:00
Veronika Polevara b7eaa6209f Delete 'TaskD04/run.py' 2023-12-10 22:05:54 +01:00
Veronika Polevara 70a8f23e6c Delete 'TaskD04/description.txt' 2023-12-10 22:05:50 +01:00
Veronika Polevara 9d06315142 Delete 'TaskD03/simple.out' 2023-12-10 22:05:41 +01:00
Veronika Polevara b77d5f4b78 Delete 'TaskD03/simple.in' 2023-12-10 22:05:36 +01:00
Veronika Polevara 2f1f8b61b2 Delete 'TaskD03/simple.exp' 2023-12-10 22:05:31 +01:00
Veronika Polevara 24f8a1cceb Delete 'TaskD03/run.py' 2023-12-10 22:05:28 +01:00
Veronika Polevara bcc5dd15cb Delete 'TaskD03/description.txt' 2023-12-10 22:05:24 +01:00
Veronika Polevara 53dd677cfb Delete 'TaskD02/simple.out' 2023-12-10 22:04:52 +01:00
Veronika Polevara a6545fcaa5 Delete 'TaskD02/simple.in' 2023-12-10 22:04:48 +01:00
Veronika Polevara 6be920f80e Delete 'TaskD02/simple.exp' 2023-12-10 22:04:44 +01:00
Veronika Polevara eece10e455 Delete 'TaskD02/run.py' 2023-12-10 22:04:40 +01:00
Veronika Polevara 6ecd654dea Delete 'TaskD02/description.txt' 2023-12-10 22:04:36 +01:00
Veronika Polevara 5fc857b78c Delete 'TaskD01/simple.out' 2023-12-10 22:04:26 +01:00
Veronika Polevara 3fd530b13b Delete 'TaskD01/simple.in' 2023-12-10 22:04:20 +01:00
Veronika Polevara 3d295d5189 Delete 'TaskD01/simple.exp' 2023-12-10 22:04:16 +01:00
Veronika Polevara 78e075793b Delete 'TaskD01/run.py' 2023-12-10 22:04:09 +01:00
Veronika Polevara 3da3b1c634 Delete 'TaskD01/description.txt' 2023-12-10 22:04:00 +01:00
Veronika Polevara f424d4529c wykonane zadania z tasku D 2023-11-25 16:08:43 +01:00
Veronika Polevara 92b31192b3 wykonane zadania z tasku D 2023-11-25 16:08:20 +01:00
Veronika Polevara ee2341d218 wykonane zadania z tasku D 2023-11-25 16:08:02 +01:00
Veronika Polevara 2d8a843df2 Upload files to 'TaskD01' 2023-11-25 16:07:14 +01:00
Veronika Polevara dc2dc557d1 Merge pull request 'wykonane zadania z tasku C' (#2) from TasksB into master
Reviewed-on: s464986/dffz-2023-s464986#2
2023-11-09 14:18:12 +01:00
Polevara Veronika d1bf33f809 wykonane zadania z tasku C 2023-11-09 14:16:19 +01:00
Veronika Polevara 11305777b3 Merge pull request 'TasksB' (#1) from TasksB into master
Reviewed-on: s464986/dffz-2023-s464986#1
2023-10-29 16:49:51 +01:00
12 changed files with 211 additions and 0 deletions

14
TaskC00/description.txt Normal file
View File

@ -0,0 +1,14 @@
Read a description of a non-deterministic finite-state automaton in the AT&T format
(without weights) from the file in the first argument.
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: python run.py test1.arg < test1.in > test1.out
Note that not all transitions must be included in description.
If no transition is given for the given state and letter, write NO.
POINTS: 3
DEADLINE: 2023-11-12 23:59:59

64
TaskC00/run.py Normal file
View File

@ -0,0 +1,64 @@
import sys
import copy
class FSA:
def __init__(self):
self.initial_state = '0'
self.final_states = set()
self.transitions = dict()
self.alphabet = set()
def add_transition(self, state_from, state_to, symbol):
if state_from in self.transitions.keys():
if symbol not in self.transitions[state_from].keys():
self.transitions[state_from][symbol] = {state_to}
else:
self.transitions[state_from][symbol] |= {state_to}
else:
self.transitions[state_from] = dict()
self.transitions[state_from][symbol] = {state_to}
def add_final_state(self, state):
self.final_states.add(state)
def get_final_states(self, string):
current_states = {self.initial_state}
for symbol in string:
new_current_states = set()
for current_state in current_states:
try:
new_current_states |= self.transitions[current_state][symbol]
except:
pass
current_states = copy.deepcopy(new_current_states)
return current_states
def accepts(self, string):
for final_state in self.get_final_states(string):
if final_state in self.final_states:
return True
return False
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip()
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
else:
fsa.add_final_state(line)
for line in sys.stdin:
line = line.rstrip()
if fsa.accepts(line):
print('YES')
else:
print('NO')

7
TaskC00/testnfa.arg Normal file
View File

@ -0,0 +1,7 @@
0 1 a
1 0 a
1 2 b
2 4 c
1 3 b
3
4

8
TaskC00/testnfa.exp Normal file
View File

@ -0,0 +1,8 @@
YES
YES
NO
NO
NO
YES
NO
YES

8
TaskC00/testnfa.in Normal file
View File

@ -0,0 +1,8 @@
abc
ab
abcd
aaaabc
aaaaaaaabc
aaaaaaabc
zzz
aaaaaaabc

8
TaskC00/testnfa.out Normal file
View File

@ -0,0 +1,8 @@
YES
YES
NO
NO
NO
YES
NO
YES

14
TaskC02/description.txt Normal file
View File

@ -0,0 +1,14 @@
Use a non deterministic finite-state automaton (FSA) engine from the TaskC00.
Create your own non deterministic FSA description to check whether the string
ends with "ab"
Don't use external files like in TaskF00 (description should be included in run file).
The alphabet is "a", "b", "C"
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 3
DEADLINE: 2023-11-12 23:59:59
REMAINDER: 1/3

64
TaskC02/run.py Normal file
View File

@ -0,0 +1,64 @@
import sys
import copy
class FSA:
def __init__(self):
self.initial_state = '0'
self.final_states = set()
self.transitions = dict()
self.alphabet = set()
def add_transition(self, state_from, state_to, symbol):
if state_from in self.transitions.keys():
if symbol not in self.transitions[state_from].keys():
self.transitions[state_from][symbol] = {state_to}
else:
self.transitions[state_from][symbol] |= {state_to}
else:
self.transitions[state_from] = dict()
self.transitions[state_from][symbol] = {state_to}
def add_final_state(self, state):
self.final_states.add(state)
def get_final_states(self, string):
current_states = {self.initial_state}
for symbol in string:
new_current_states = set()
for current_state in current_states:
try:
new_current_states |= self.transitions[current_state][symbol]
except:
pass
current_states = copy.deepcopy(new_current_states)
return current_states
def accepts(self, string):
for final_state in self.get_final_states(string):
if final_state in self.final_states:
return True
return False
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip()
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
else:
fsa.add_final_state(line)
for line in sys.stdin:
line = line.rstrip()
if fsa.accepts(line):
print('YES')
else:
print('NO')

6
TaskC02/test.arg Normal file
View File

@ -0,0 +1,6 @@
0 0 a
0 0 b
0 0 c
0 1 a
1 2 b
2

6
TaskC02/test.exp Normal file
View File

@ -0,0 +1,6 @@
YES
NO
YES
NO
YES
NO

6
TaskC02/test.in Normal file
View File

@ -0,0 +1,6 @@
ab
a
abbab
bbbbb
ababaab
b

6
TaskC02/test.out Normal file
View File

@ -0,0 +1,6 @@
YES
NO
YES
NO
YES
NO