Compare commits

...

33 Commits

Author SHA1 Message Date
29e223fe0d F 2024-01-07 12:16:30 +01:00
8369543e6f Merge https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2024-01-03 22:46:15 +01:00
1129cd6540 Task description fix. 2023-12-29 19:43:44 +01:00
023285f6ab Fixes 2023-12-11 22:16:59 +01:00
5cb32d1aa0 Before labs 5 2023-12-11 00:03:25 +01:00
ef113e811d ex4 2023-12-10 19:09:40 +01:00
a8350f1156 Merge https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2023-12-10 14:21:39 +01:00
47c34989bc Fix run_report.py 2023-11-30 21:30:32 +01:00
b01415db32 Before labs 4 2023-11-27 15:54:30 +01:00
6b3df7cf2b ex D 2023-11-26 12:43:45 +01:00
abd0e8fd7f exercise D 2023-11-26 12:43:04 +01:00
a84a1dcf10 Merge branch 'master' of https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2023-11-25 20:34:07 +01:00
dc11d77751 Usuń 'TaskB05/run.py' 2023-11-25 20:19:58 +01:00
0bedc18d06 Usuń 'TaskB03/run.py' 2023-11-25 20:19:39 +01:00
9908d0b89b Merge branch 'master' of https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2023-11-25 19:59:47 +01:00
b3811ac6fe Fixes 2023-11-24 20:39:14 +01:00
92d827acdf Usuń 'TaskB05/fsa_description.arg' 2023-11-22 22:20:44 +01:00
d3a17e75f2 Usuń 'TaskB03/fsa_description.arg' 2023-11-22 22:20:00 +01:00
ceb261d9e8 Usuń 'TaskB01/fsa_description.arg' 2023-11-22 22:17:18 +01:00
69ec0933db After labs 3 2023-11-13 22:37:53 +01:00
5c8fc0ab48 Merge https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023 2023-11-12 22:42:39 +01:00
3723e7f8df Before labs 3 2023-11-12 21:47:02 +01:00
403022723a Fixes 2023-11-12 15:41:40 +01:00
10b976d87b Merge branch 'master' of https://git.wmi.amu.edu.pl/bfijalkowski/DJFZ-2023
 Conflicts:
	README.md
	TaskB00/run.py
	TaskC01/test.exp
2023-11-11 20:07:13 +01:00
944c5d0b39 Merge pull request 'Labs -> master' (#1) from Labs into master
Reviewed-on: bfijalkowski/DJFZ-2023#1
2023-11-11 19:20:11 +01:00
9a8a7dcb3f After labs 2 2023-11-03 21:04:26 +01:00
84ec629d9b Delete .idea files 2023-11-03 20:48:10 +01:00
424e731b8d ex1 done 2023-11-02 11:16:43 +01:00
a4e0846092 Fix tasks B deadline 2023-10-30 16:08:46 +01:00
3a3e9cf78e Before Labs 2 2023-10-29 22:59:51 +01:00
9ed88f3d76 After Labs1 2023-10-18 22:19:28 +02:00
e090453c6b After Labs1 2023-10-18 22:13:52 +02:00
0891a918c7 Labs1 2023-10-15 16:42:49 +02:00
314 changed files with 989372 additions and 49 deletions

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JpaBuddyIdeaProjectConfig">
<option name="renamerInitialized" value="true" />
</component>
</project>

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_18" project-jdk-name="Python 3.11 (PythonTest)" project-jdk-type="Python SDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="ProjectType">
<option name="id" value="jpab" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/DJFZ-2023.iml" filepath="$PROJECT_DIR$/.idea/DJFZ-2023.iml" />
</modules>
</component>
</project>

278
README.md
View File

@ -23,7 +23,7 @@ nie będzie wpływał na ocenę, ale bez zdanego kolowkium nie da się zaliczyć
Proszę stworzyć prywatne repozytorium na https://git.wmi.amu.edu.pl/ o nazwie djfz-2023-sNRINDEKSU oraz dać
prawa do odczytu użytkownikowi bfijalkowski (prowadzący przedmiot). W NRINDEKSU proszę wpisać swój nr indeksu, np. djfz-2023-s123456.
Następnie w swoim repozytorium proszę spullować niniejsze repozytorium: `git pull git@git.wmi.amu.edu.pl:bfijalkowski/DJFZ-2023.git`
Następnie w swoim repozytorium proszę zforkować niniejsze repozytorium: `git pull git@git.wmi.amu.edu.pl:bfijalkowski/DJFZ-2023.git`
W ten sposób będziemy aktualizować zadania co zajęcia.
Proszę rozwiązać zadanie TASKX02 lub TASKX03 w zależności od numeru indeksu. W tym celu należy dodać plik `run.py`
@ -48,3 +48,279 @@ B00 - zadanie wykonywane wspólnie na zajęciach
B01-B04, B06-B09 - po jedno dla każdego
B05 - jedno dla wszystkich
## Zajęcia 2 30.10.2023 Automaty niedeterministyczne skończone
C00 - zadanie wykonywane wspólnie na zajęciach
C01-C03, C04-C06 - po jedno dla każdego
## Zajęcia 3 13.11.2023 Wyrażenia regularne
D01 - D04 - do wykonania przez każdego
Dokumentacja wyrażeń regularnych w python3: https://docs.python.org/3/library/re.html
### Podstawowe funkcje
search - zwraca pierwsze dopasowanie w napisie
findall - zwraca listę wszystkich dopasowań (nienakładających się na siebie)
match - zwraca dopasowanie od początku string
To tylko podstawowe funkcje, z których będziemy korzystać. W dokumentacji opisane są wszystkie.
### Obiekt match
```
import re
answer = re.search('na','banan')
print(answer)
print(type(answer))
print(answer.start())
print(answer.end())
print(answer.group())
answer = re.search('na','kabanos')
print(answer)
if answer:
print(answer.group())
else:
pass
```
### Metaznaki
- [] - zbiór znaków
- . - jakikolwiek znak
- ^ - początek napisu
- $ - koniec napisu
- ? - znak występuje lub nie występuje
- \* - zero albo więcej pojawień się
- \+ - jeden albo więcej pojawień się
- {} - dokładnie tyle pojawień się
- | - lub
- () - grupa
- \ -znak ucieczki
- \d digit
- \D nie digit
- \s whitespace
- \S niewhitespace
### Flagi
Można użyć specjalnych flag, np:
`re.search('ma', 'AlA Ma KoTa', re.IGNORECASE)`.
### Przykłady (objaśnienia na laboratoriach)
```
import re
text = 'Ala ma kota i hamak, oraz 150 bananów.'
re.search('ma',text)
re.match('ma',text)
re.match('Ala ma',text)
re.findall('ma',text)
re.findall('[mn]a',text)
re.findall('[0-9]',text)
re.findall('[0-9abc]',text)
re.findall('[a-z][a-z]ma[a-z]',text)
re.findall('[a-zA-Z][a-zA-Z]ma[a-zA-z0-9]',text)
re.findall('\d',text)
re.search('[0-9][0-9][0-9]',text)
re.search('[\d][\d][\d]',text)
re.search('\d{2}',text)
re.search('\d{3}',text)
re.search('\d+',text)
re.search('\d+ bananów',text)
re.search('\d* bananów','Ala ma dużo bananów')
re.search('\d* bananów',text)
re.search('ma \d? bananów','Ala ma 5 bananów')
re.search('ma ?\d? bananów','Ala ma bananów')
re.search('ma( \d)? bananów','Ala ma bananów')
re.search('\d+ bananów','Ala ma 10 bananów albo 20 bananów')
re.search('\d+ bananów$','Ala ma 10 bananów albo 20 bananów')
text = 'Ala ma kota i hamak, oraz 150 bananów.'
re.search('\d+ bananów',text)
re.search('\d+\sbananów',text)
re.search('kota . hamak',text)
re.search('kota . hamak','Ala ma kota z hamakiem')
re.search('kota .* hamak','Ala ma kota lub hamak')
re.search('\.',text)
re.search('kota|psa','Ala ma kota lub hamak')
re.findall('kota|psa','Ala ma kota lub psa')
re.search('kota (i|lub) psa','Ala ma kota lub psa')
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(0)
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(1)
re.search('mam (kota).*(kota|psa)','Ja mam kota. Ala ma psa.').group(2)
```
### Przykłady wyrażenia regularne 2 (objaśnienia na laboratoriach)
#### ^
```
re.search('[0-9]+', '123-456-789')
re.search('[^0-9][0-9]+[^0-9]', '123-456-789')
```
#### cudzysłów
'' oraz "" - oznaczają to samo w pythonie
' ala ma psa o imieniu "Burek"'
" ala ma psa o imieniu 'Burek' "
' ala ma psa o imieniu \'Burek\' '
" ala ma psa o imieniu \"Burek\" "
#### multiline string
#### raw string
przy raw string znaki \ traktowane są jako zwykłe znaki \
chociaż nawet w raw string nadal są escapowane (ale wtedy \ pozostają również w stringu bez zmian)
https://docs.python.org/3/reference/lexical_analysis.html
dobra praktyka - wszędzie escapować
```
'\\'
print('\\')
r'\\'
print(r'\\')
print("abcd")
print("ab\cd")
print(r"ab\cd")
print("ab\nd")
print(r"ab\nd")
print("\"")
print(r"\"")
print("\")
print(r"\")
re.search('\\', r'a\bc')
re.search(r'\\', r'a\bc')
re.search('\\\\', r'a\bc')
```
## Zajęcia 4 27.11.2023 Wyrażenia regularne 2
E00 - E09 - po jedno dla każdego
E10 - E36 - po jedno dla każdego
E37 - E43 - po jedno dla każdego
E44 - E48 - po jedno dla każdego
## Zajęcia 5 11.12.2023 Wyrażenia regularne 3
F00 - F05 - do wykonania przez każdego
Proszę o przekopiowanie sobie pliku polish_wiki_excerpt.in z zadania F00 do katalogów z pozostałymi zadaniami
#### RE SUB
```
re.sub(pattern, replacement, string)
re.sub('a','b', 'ala ma kota')
```
#### backreferencje:
```
re.search(r' \d+ \d+', 'ala ma 41 41 kota')
re.search(r' \d+ \d+', 'ala ma 41 123 kota')
re.search(r' (\d+) \1', 'ala ma 41 41 kota')
re.search(r' (\d+) \1', 'ala ma 41 123 kota')
```
#### lookahead ( to sa takie assercje):
```
re.search(r'ma kot', 'ala ma kot')
re.search(r'ma kot(?=[ay])', 'ala ma kot')
re.search(r'ma kot(?=[ay])', 'ala ma kotka')
re.search(r'ma kot(?=[ay])', 'ala ma koty')
re.search(r'ma kot(?=[ay])', 'ala ma kota')
re.search(r'ma kot(?![ay])', 'ala ma kot')
re.search(r'ma kot(?![ay])', 'ala ma kotka')
re.search(r'ma kot(?![ay])', 'ala ma koty')
re.search(r'ma kot(?![ay])', 'ala ma kota')
```
#### named groups
```
r = re.search(r'ma (?P<ilepsow>\d+) kotow i (?P<ilekotow>\d+) psow', 'ala ma 100 kotow i 200 psow')
r.groups()
r.groups('ilepsow')
r.groups('ilekotow')
```
#### re.split
```
('a,b.c,d').split(',')
('a,b.c,d').split(',')
('a,b.c,d').split(',.')
re.split(r',', 'a,b.c,d')
re.split(r'[.,]', 'a,b.c,d')
```
#### \w word character
```
\w - matchuje Unicod word character , jeżeli flaga ASCII to [a-zA-Z0-9_]
\w - odwrotne do \W, jezeli flaga ASCI to [^a-zA-Z0-9_]
re.findall(r'\w+', 'ala ma 3 koty.')
re.findall(r'\W+', 'ala ma 3 koty.')
```
#### początek albo koniec słowa | word boundary
```
re.search(r'\bkot\b', 'Ala ma kota')
re.search(r'\bkot\b', 'Ala ma kot')
re.search(r'\bkot\b', 'Ala ma kot.')
re.search(r'\bkot\b', 'Ala ma kot ')
re.search(r'\Bot\B', 'Ala ma kot ')
re.search(r'\Bot\B', 'Ala ma kota ')
```
#### MULTILINE
```
re.findall(r'^Ma', 'Ma kota Ala\nMa psa Jacek')
re.findall(r'^Ma', 'Ma kota Ala\nMa psa Jacek', re.MULTILINE)

63
TaskB00/run.py Normal file
View File

@ -0,0 +1,63 @@
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że 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():
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
elif len(line.split('\t')) == 1:
fsa.add_final_state(line)
else:
assert False
for line in sys.stdin:
line = line.rstrip()
for symbol in line:
if symbol not in fsa.alphabet:
assert False
if fsa.accepts(line):
print('YES')
else:
print('NO')

View File

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

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 2
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 1/4

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 2
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 2/4

View File

@ -10,5 +10,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 2
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 3/4

View File

@ -0,0 +1,5 @@
0 1 0
0 0 1
1 0 0
1 1 1
0

59
TaskB03/run.py Normal file
View File

@ -0,0 +1,59 @@
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że 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():
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
if __name__ == "__main__":
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
elif len(line.split('\t')) == 1:
fsa.add_final_state(line)
else:
assert False
for line in sys.stdin:
stripped_line = line.strip()
if fsa.accepts(stripped_line):
print('YES')
else:
print('NO')

View File

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

View File

@ -10,5 +10,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 2
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 0/4

View File

@ -9,4 +9,4 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 2
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59

View File

@ -0,0 +1,56 @@
0 0 0
0 1 1
0 0 2
0 0 3
0 0 4
0 0 5
0 0 6
0 0 7
0 0 8
0 0 9
0 0 x
1 0 0
1 1 1
1 0 2
1 0 3
1 0 4
1 0 5
1 0 6
1 0 7
1 0 8
1 2 9
1 0 x
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
2 0 x
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
3 0 x
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
4

File diff suppressed because it is too large Load Diff

59
TaskB05/run.py Normal file
View File

@ -0,0 +1,59 @@
import sys
class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że 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():
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
if __name__ == "__main__":
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
elif len(line.split('\t')) == 1:
fsa.add_final_state(line)
else:
assert False
for line in sys.stdin:
stripped_line = line.strip()
if fsa.accepts(stripped_line):
print('YES')
else:
print('NO')

View File

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

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 3
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 0/4

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 3
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 1/4

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 3
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 2/4

View File

@ -9,5 +9,5 @@ If a string is accepted by the
automaton, write YES, otherwise- write NO.
POINTS: 3
DEADLINE: 2020-11-07 23:59:00
DEADLINE: 2023-10-29 23:59:59
REMAINDER: 3/4

217
TaskB09/fsa_description.arg Normal file
View File

@ -0,0 +1,217 @@
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 h
0 0 i
0 0 j
0 0 k
0 0 l
0 1 m
0 0 n
0 0 o
0 0 p
0 0 q
0 0 r
0 0 s
0 0 t
0 0 u
0 0 v
0 0 w
0 0 x
0 0 y
0 0 z
0 0
1 2 a
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
1 0 h
1 0 i
1 0 j
1 0 k
1 0 l
1 0 m
1 0 n
1 0 o
1 0 p
1 0 q
1 0 r
1 0 s
1 0 t
1 0 u
1 0 v
1 0 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class FSA:
def __init__(self):
self.initial_state = '0' # zakładamy dla uproszczenia, że 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():
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
if self.get_final_state(string) in self.final_states:
return True
else:
return False
if __name__ == "__main__":
fsa = FSA()
table = open(sys.argv[1])
for line in table:
line = line.rstrip('\n')
if len(line.split('\t')) == 3:
a, b, c = line.split('\t')
fsa.add_transition(a, b, c)
fsa.alphabet.add(c)
elif len(line.split('\t')) == 1:
fsa.add_final_state(line)
else:
assert False
for line in sys.stdin:
stripped_line = line.strip()
if fsa.accepts(stripped_line):
print('YES')
else:
print('NO')

View File

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

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

67
TaskC00/run.py Normal file
View File

@ -0,0 +1,67 @@
import sys
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
current_states = {self.initial_state}
for symbol in string:
next_states = set()
for state in current_states:
if state in self.transitions and symbol in self.transitions[state]:
next_states |= self.transitions[state][symbol]
current_states = next_states
return bool(current_states.intersection(self.final_states))
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
TaskC01/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 second letter
from right is 'b'.
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: 0/3

6
TaskC01/test.exp Normal file
View File

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

6
TaskC01/test.in Normal file
View File

@ -0,0 +1,6 @@
abc
abbc
bca
b
abaa
aaacbb

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

67
TaskC02/run.py Normal file
View File

@ -0,0 +1,67 @@
import sys
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_state(self, string):
current_state = self.initial_state
for symbol in string:
current_state = self.transitions[current_state][symbol]
return current_state
def accepts(self, string):
current_states = {self.initial_state}
for symbol in string:
next_states = set()
for state in current_states:
if state in self.transitions and symbol in self.transitions[state]:
next_states |= self.transitions[state][symbol]
current_states = next_states
return bool(current_states.intersection(self.final_states))
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')

11
TaskC02/test.arg Normal file
View File

@ -0,0 +1,11 @@
0 0 a
0 0 b
0 0 c
0 1 a
1 1 a
1 2 b
1 0 c
2 0 a
2 0 b
2 0 c
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

14
TaskC03/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
contains "abc"
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: 2/3

7
TaskC03/test.exp Normal file
View File

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

7
TaskC03/test.in Normal file
View File

@ -0,0 +1,7 @@
abc
acabc
acabccb
abbab
bbbbb
ababaab
bc

0
TaskC03/test.out Normal file
View File

28
TaskC04/description.txt Normal file
View File

@ -0,0 +1,28 @@
Deterministic automaton III
===========================
Read a description of a finite-state automaton in the AT&T format
(without weights) from the file in the first argument. Then, read strings from the
standard input. If a string is
accepted by the automaton, write TRUE, a space and the string on the
standard output, otherwise — write FALSE, a space and the string.
If there is a non-determinism in the automaton, the first transition should be chosen.
The automaton can contain epsilon transitions ("<eps>" instead of a
character). They should be interpreted as follows: an epsilon
transition can be used (without "eating" a character from the input),
if there is no other transition applicable. You can assume that there
is at most one epsilon transition from a given state and that there
are no cycles with epsilon transition.
Your program does not have to check whether the description is correct
and whether the automaton is deterministic.
long.arg - this automaton accepts two texts - "aaaa" and "a" replicated 4038 times.
simple1.arg - simple automaton accepting only text "abc"
simple2.arg - automaton accepting text "ab*c" (b replicated any number of times) and "kot"
POINTS: 3
DEADLINE: 2023-11-12 23:59:59
REMAINDER: 0/3

8
TaskC04/eps.arg Normal file
View File

@ -0,0 +1,8 @@
0 1 a
1 0 a
1 2 b
2 4 c
1 3 <eps>
3 4 d
3
4

10
TaskC04/eps.exp Normal file
View File

@ -0,0 +1,10 @@
TRUE a
FALSE aa
TRUE aaa
TRUE abc
TRUE aaabc
FALSE aaabcd
FALSE aabc
FALSE abd
TRUE ad
FALSE aad

10
TaskC04/eps.in Normal file
View File

@ -0,0 +1,10 @@
a
aa
aaa
abc
aaabc
aaabcd
aabc
abd
ad
aad

4040
TaskC04/long.arg Normal file

File diff suppressed because it is too large Load Diff

7
TaskC04/long.exp Normal file
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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
xyz
aba
a

4
TaskC04/simple1.arg Normal file
View File

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

8
TaskC04/simple1.exp Normal file
View File

@ -0,0 +1,8 @@
FALSE a
FALSE ab
TRUE abc
FALSE abcd
FALSE aaaaab
TRUE abc
FALSE xyz
FALSE 0

8
TaskC04/simple1.in Normal file
View File

@ -0,0 +1,8 @@
a
ab
abc
abcd
aaaaab
abc
xyz
0

8
TaskC04/simple2.arg Normal file
View File

@ -0,0 +1,8 @@
0 1 a
1 1 b
1 2 c
0 3 k
3 4 o
4 5 t
2
5

9
TaskC04/simple2.exp Normal file
View File

@ -0,0 +1,9 @@
TRUE kot
TRUE ac
TRUE abc
TRUE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
FALSE abcd
FALSE abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc
FALSE kotek
FALSE kotabc
TRUE kot

9
TaskC04/simple2.in Normal file
View File

@ -0,0 +1,9 @@
kot
ac
abc
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbc
abcd
abbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbcccccc
kotek
kotabc
kot

52
TaskC05/description.txt Normal file
View File

@ -0,0 +1,52 @@
Dictionary
==========
Your program should read a finite-state automaton from file in the first argument.
The automaton is deterministic, you can assume it does not contain
cycles.
Each automaton path is labeled with a symbol sequence of the following form:
<input word>;<description>
e.g.:
biały;ADJ
dom;N
piła;N
piła;V
stali;N
stali;V
stali;ADJ
Next you should read words from the standard input.
For each word, you should all automaton
paths that begin a given word, the following symbol is ';'
(semicolon), e.g. for the word 'dom' we are looking for paths
beginning with 'dom;'. If there is no such path, the following message
should be printed:
<input word>;OOV
For instance, for the automaton given above and the input:
budynek
dom
piła
we should get:
budynek;OOV
dom;N
piła;N
piła;V
If there is more than one path for a given word, they should be given in alphabetical order.
The program does not have to check whether the automaton is correct
and whether it is deterministic and does not contain cycles.
POINTS: 3
DEADLINE: 2023-11-12 23:59:59
REMAINDER: 1/3

31
TaskC05/elem.arg Normal file
View File

@ -0,0 +1,31 @@
0 1 b
0 2 d
0 3 p
0 4 s
1 5 i
2 6 o
3 7 i
4 8 t
5 9 a
6 10 m
7 11 ł
8 12 a
9 13 ł
10 14 ;
11 15 a
12 16 l
13 17 y
14 24 N
15 18 ;
16 19 i
17 20 ;
18 24 N
18 24 V
19 21 ;
20 22 A
21 22 A
21 24 N
21 24 V
22 23 D
23 24 J
24

1
TaskC05/elem.exp Normal file
View File

@ -0,0 +1 @@
dom;N

1
TaskC05/elem.in Normal file
View File

@ -0,0 +1 @@
dom

0
TaskC05/elem.out Normal file
View File

15125
TaskC05/medium.arg Normal file

File diff suppressed because it is too large Load Diff

7
TaskC05/medium.exp Normal file
View File

@ -0,0 +1,7 @@
arbuz;N
arbuza;N
arbuzowi;ADJ
arbuzowi;N
azylant;N
azylanci;N
azylantowie;OOV

6
TaskC05/medium.in Normal file
View File

@ -0,0 +1,6 @@
arbuz
arbuza
arbuzowi
azylant
azylanci
azylantowie

0
TaskC05/medium.out Normal file
View File

31
TaskC05/multi.arg Normal file
View File

@ -0,0 +1,31 @@
0 1 b
0 2 d
0 3 p
0 4 s
1 5 i
2 6 o
3 7 i
4 8 t
5 9 a
6 10 m
7 11 ł
8 12 a
9 13 ł
10 14 ;
11 15 a
12 16 l
13 17 y
14 24 N
15 18 ;
16 19 i
17 20 ;
18 24 N
18 24 V
19 21 ;
20 22 A
21 22 A
21 24 N
21 24 V
22 23 D
23 24 J
24

2
TaskC05/multi.exp Normal file
View File

@ -0,0 +1,2 @@
piła;N
piła;V

1
TaskC05/multi.in Normal file
View File

@ -0,0 +1 @@
piła

0
TaskC05/multi.out Normal file
View File

31
TaskC05/oov.arg Normal file
View File

@ -0,0 +1,31 @@
0 1 b
0 2 d
0 3 p
0 4 s
1 5 i
2 6 o
3 7 i
4 8 t
5 9 a
6 10 m
7 11 ł
8 12 a
9 13 ł
10 14 ;
11 15 a
12 16 l
13 17 y
14 24 N
15 18 ;
16 19 i
17 20 ;
18 24 N
18 24 V
19 21 ;
20 22 A
21 22 A
21 24 N
21 24 V
22 23 D
23 24 J
24

1
TaskC05/oov.exp Normal file
View File

@ -0,0 +1 @@
budynek;OOV

1
TaskC05/oov.in Normal file
View File

@ -0,0 +1 @@
budynek

0
TaskC05/oov.out Normal file
View File

0
TaskC05/run.py Normal file
View File

24
TaskC06/description.txt Normal file
View File

@ -0,0 +1,24 @@
Paths
======
Your program should read a finite-state automaton from
the standard input.
The automaton is deterministic, you can assume it does not contain
cycles. The automaton alphabet is the set of Polish lower-case letters
(English letters plus: ą, ć, ę, ł, ń, ó, ś, ź and ż).
Your program should print, on standard output, all the paths of the
automaton in alphabetical order (to be precise: order induced by byte
codes of strings, not according to the standard Polish order). "Print
a path" means print a text line containing all subsequent characters.
The program does not have to check whether the automaton is correct
and whether it is deterministic and does not contain cycles.
Weights (if any) should be disregarded.
NOTE 1. You can add `LANG=C sort` to your Bash wrapper for the write sort.
POINTS: 3
DEADLINE: 2023-11-12 23:59:59
REMAINDER: 2/3

50648
TaskC06/medium.exp Normal file

File diff suppressed because it is too large Load Diff

14774
TaskC06/medium.in Normal file

File diff suppressed because it is too large Load Diff

0
TaskC06/medium.out Normal file
View File

4
TaskC06/small.exp Normal file
View File

@ -0,0 +1,4 @@
biały
dom
piła
stali

18
TaskC06/small.in Normal file
View File

@ -0,0 +1,18 @@
0 1 b
0 2 d
0 3 p
0 4 s
1 5 i
2 6 o
3 7 i
4 8 t
5 9 a
6 14 m
7 10 ł
8 11 a
9 12 ł
10 14 a
11 13 l
12 14 y
13 14 i
14

0
TaskC06/small.out Normal file
View File

3
TaskC06/small2.exp Normal file
View File

@ -0,0 +1,3 @@
biały
piła
stali

18
TaskC06/small2.in Normal file
View File

@ -0,0 +1,18 @@
0 1 b
0 2 d
0 3 p
0 4 s
1 5 i
2 6 o
3 7 i
4 8 t
5 9 a
6 15 m
7 10 ł
8 11 a
9 12 ł
10 14 a
11 13 l
12 14 y
13 14 i
14

0
TaskC06/small2.out Normal file
View File

5
TaskD01/description.txt Normal file
View File

@ -0,0 +1,5 @@
Write a program to find lines containing the word "Hamlet".
Do use regular expressions.
POINTS: 1
DEADLINE: 2023-11-26 23:59:59

7
TaskD01/run.py Normal file
View File

@ -0,0 +1,7 @@
import re
import sys
for line in sys.stdin:
stripped_line = line.strip()
if re.search("Hamlet", stripped_line):
print(stripped_line)

2
TaskD01/simple.exp Normal file
View File

@ -0,0 +1,2 @@
Here comes Hamlet
Hamlet Hamlet again

3
TaskD01/simple.in Normal file
View File

@ -0,0 +1,3 @@
Here comes Hamlet
ABC
Hamlet Hamlet again

2
TaskD01/simple.out Normal file
View File

@ -0,0 +1,2 @@
Here comes Hamlet
Hamlet Hamlet again

7
TaskD02/description.txt Normal file
View File

@ -0,0 +1,7 @@
Write a program to find lines containing the word "pies" separated by spaces.
The word does not need to have space on the left if it is the line beginning or space on the right if it is line ending.
Return line no matter of word "pies" casing.
Do use regular expressions.
POINTS: 1
DEADLINE: 2023-11-26 23:59:59

7
TaskD02/run.py Normal file
View File

@ -0,0 +1,7 @@
import re
import sys
for line in sys.stdin:
stripped_line = line.strip()
if re.search(r"\bpies\b", stripped_line, re.IGNORECASE):
print(stripped_line)

3
TaskD02/simple.exp Normal file
View File

@ -0,0 +1,3 @@
Pies ma Alę
Kot i pies to zwierzęta
pies

5
TaskD02/simple.in Normal file
View File

@ -0,0 +1,5 @@
Pies ma Alę
Ala ma psa
tu nic nie ma
Kot i pies to zwierzęta
pies

3
TaskD02/simple.out Normal file
View File

@ -0,0 +1,3 @@
Pies ma Alę
Kot i pies to zwierzęta
pies

6
TaskD03/description.txt Normal file
View File

@ -0,0 +1,6 @@
Write a program to find lines containing date from 1900 to 1999 in format '19XX r.' no matter what on the left or right of the expression.
Note that part ' r.' is obligatory.
Do use regular expressions.
POINTS: 1
DEADLINE: 2023-11-26 23:59:59

7
TaskD03/run.py Normal file
View File

@ -0,0 +1,7 @@
import re
import sys
for line in sys.stdin:
stripped_line = line.strip()
if re.search("19[0-9][0-9] r\.", stripped_line, re.IGNORECASE):
print(stripped_line)

3
TaskD03/simple.exp Normal file
View File

@ -0,0 +1,3 @@
Kiedyś był 1934 r.
Kiedyś był 1934 r.fsdfsdfsdf
1934 r. to jakaś data

Some files were not shown because too many files have changed in this diff Show More