Compare commits

...

89 Commits

Author SHA1 Message Date
IgnBys
5e5500d0ee TaskF05 F04 2024-01-20 23:38:38 +01:00
IgnBys
d7877f4f5f TaskF04 2024-01-20 17:32:06 +01:00
IgnBys
3f957f6706 TaskF03 2024-01-08 14:38:30 +01:00
IgnBys
80be8e6e8b TaskF03 2024-01-08 14:28:56 +01:00
IgnBys
e80ed8ce6c TaskF01 2024-01-08 13:06:56 +01:00
IgnBys
528bee3224 TaskF00 2024-01-08 12:43:44 +01:00
IgnBys
51601587c8 Merge https://github.com/duszekjk/jezykiformalne 2024-01-08 12:09:54 +01:00
IgnBys
f74d717d03 This tasks were made month ago but i remembered upload to git - I am so sorry! 2024-01-08 12:05:14 +01:00
Jacek Kałużny
8fb54512d7
Add files via upload 2024-01-08 11:27:35 +01:00
Jacek Kałużny
2a11de62de
Add files via upload 2023-12-11 11:42:57 +01:00
Jacek Kałużny
f0b3128a5d
Add files via upload 2023-12-11 11:41:28 +01:00
IgnBys
c5d488229f D01 and other fixes 2023-11-27 22:38:20 +01:00
42e3416d3f Fixed D02 2023-11-27 13:21:09 +01:00
008b497bd8 TaskD03 2023-11-27 13:19:39 +01:00
500e6f1837 TaskD02 2023-11-27 13:06:53 +01:00
6091e5a846 TaskD01 2023-11-27 12:47:50 +01:00
147ec79a59 Merge https://github.com/duszekjk/jezykiformalne 2023-11-27 12:35:03 +01:00
Jacek Kałużny
ffdd599310
Add files via upload 2023-11-27 12:29:45 +01:00
b5a902c2bb Merge https://github.com/duszekjk/jezykiformalne 2023-11-27 12:22:03 +01:00
e1c4f66bc1 Merge .idea directory changes from remote repository 2023-11-27 12:16:05 +01:00
Jacek Kałużny
e4b645e080
Add files via upload 2023-11-27 11:00:24 +01:00
Jacek Kałużny
3eb63c638d
Update description.txt 2023-11-27 10:58:05 +01:00
Jacek Kałużny
5b5256e00a
Update description.txt 2023-11-27 10:57:38 +01:00
Jacek Kałużny
a1cee0ae11
Update description.txt 2023-11-27 10:57:10 +01:00
Jacek Kałużny
ef01b8e788
Update description.txt 2023-11-27 10:56:43 +01:00
Jacek Kałużny
5b7ca344ae
Add files via upload 2023-11-27 10:56:21 +01:00
IgnBys
eb3db4869e C06 fixed 2023-11-25 23:47:56 +01:00
IgnBys
7e83b40edd Fixed C01-03 2023-11-25 23:43:26 +01:00
IgnBys
fd6c90a06a TaskC06 2023-11-24 23:19:27 +01:00
IgnBys
18ee7b7212 Gixed C05 2023-11-21 17:15:47 +01:00
IgnBys
96e7136c5e Ended TaskC05 2023-11-21 17:14:36 +01:00
IgnBys
bb0d611890 C04 fixed 2023-11-19 19:05:52 +01:00
IgnBys
8c52521f2b TaskC04 2023-11-19 19:01:41 +01:00
IgnBys
2eed53581b Fixed C00-C03 2023-11-19 17:38:19 +01:00
IgnBys
b3c8c2cab0 Added run.py files in every TaskC0* 2023-11-16 21:40:35 +01:00
IgnBys
56bcb5e4c5 TaskC00 ended with recursion problem 2023-11-14 20:09:36 +01:00
IgnBys
21b8220725 Merge https://github.com/duszekjk/jezykiformalne 2023-11-13 11:55:30 +01:00
Jacek Kałużny
c1d39e1306
Update description.txt 2023-11-13 10:38:48 +01:00
Jacek Kałużny
2b98340896
Update description.txt 2023-11-13 10:38:21 +01:00
Jacek Kałużny
ce0c53d50a
Update description.txt 2023-11-13 10:35:56 +01:00
Jacek Kałużny
c9335bdb9f
Update description.txt 2023-11-13 10:34:29 +01:00
Jacek Kałużny
dcf45a1d54
Update description.txt 2023-11-13 10:34:05 +01:00
Jacek Kałużny
4f03509917
Update description.txt 2023-11-13 10:33:49 +01:00
Jacek Kałużny
807770dd92
Update description.txt 2023-11-13 10:33:30 +01:00
Jacek Kałużny
576a05281f
Update description.txt 2023-11-13 10:31:04 +01:00
Jacek Kałużny
55a1a16560
Add files via upload 2023-11-13 10:29:11 +01:00
IgnBys
661237941d Tasks B07-B09 2023-11-08 21:52:16 +01:00
IgnBys
9c1cc64427 Tasks B04-B06 2023-11-08 20:54:47 +01:00
IgnBys
277d53a17b TaskB03 ended 2023-11-08 19:24:38 +01:00
IgnBys
7f64e8abdc TaskB02 ended 2023-11-08 19:11:31 +01:00
IgnBys
ded56f2560 Last editing TaskB01 2023-11-08 19:05:04 +01:00
IgnBys
21f9d845cb Resolve merge conflicts 2023-11-08 19:03:33 +01:00
IgnBys
46ec84e1ee TaskB00 and TaskB01 were edited 2023-11-08 19:00:27 +01:00
IgnBys
a9af5e8bc2 TaskB00 edited 2023-11-08 18:50:38 +01:00
IgnBys
ee6e76bf2e TaskB01 ended 2023-11-08 18:48:12 +01:00
IgnBys
5e460ef202 Edited TaskB00 and edded READ file 2023-11-01 23:04:51 +01:00
IgnBys
81cb332f8a Merge branch 'master' of https://git.wmi.amu.edu.pl/s473579/jfz-2023-s473579 2023-11-01 22:44:08 +01:00
IgnBys
81e16658b9 TaskB00 2023-11-01 22:43:37 +01:00
24a929795d Usuń 'test1.out' 2023-11-01 22:41:44 +01:00
8d120e1806 Usuń 'test1.in' 2023-11-01 22:41:38 +01:00
IgnBys
518de0b02a Merge branch 'master' of https://git.wmi.amu.edu.pl/s473579/jfz-2023-s473579 2023-11-01 22:41:21 +01:00
IgnBys
0d51b47582 TaskB00 2023-11-01 22:41:04 +01:00
de8d0b6a66 Usuń 'test1.exp' 2023-11-01 22:40:45 +01:00
d027c0f9a2 Usuń 'run.py' 2023-11-01 22:40:40 +01:00
6236853103 Usuń 'fsa_description.arg' 2023-11-01 22:40:35 +01:00
ae7bdda803 Usuń 'description.txt' 2023-11-01 22:40:29 +01:00
IgnBys
26b4b6552e Merge branch 'master' of https://git.wmi.amu.edu.pl/s473579/jfz-2023-s473579 2023-11-01 22:39:38 +01:00
IgnBys
e87d5b53bd TaskB00 2023-11-01 22:36:00 +01:00
IgnBys
6cc8ddc5b7 Merge https://github.com/duszekjk/jezykiformalne 2023-11-01 17:16:46 +01:00
Jacek Kałużny
2b37e5c4cf
Update README.md 2023-10-30 14:23:44 +01:00
Jacek Kałużny
39345a1424
Update description.txt 2023-10-30 09:54:23 +01:00
Jacek Kałużny
713fa2349d
Update description.txt 2023-10-30 09:51:14 +01:00
Jacek Kałużny
fa7060ad43
Update description.txt 2023-10-30 09:50:39 +01:00
Jacek Kałużny
f11377a4b5
Update description.txt 2023-10-30 09:50:10 +01:00
Jacek Kałużny
3e4026d2db
Update README.md 2023-10-30 09:49:37 +01:00
Jacek Kałużny
cfb4d0806d
Update README.md 2023-10-30 09:49:22 +01:00
Jacek Kałużny
4b34cb1d3a
Update description.txt 2023-10-30 09:48:26 +01:00
Jacek Kałużny
60e52dd992
Update description.txt 2023-10-30 09:47:59 +01:00
Jacek Kałużny
fec8352787
Update description.txt 2023-10-30 09:47:03 +01:00
Jacek Kałużny
b12c09ad32
Update description.txt 2023-10-30 09:46:20 +01:00
Jacek Kałużny
85c35b6bdf
Update description.txt 2023-10-30 09:45:07 +01:00
Jacek Kałużny
b2809dd921
Update description.txt 2023-10-30 09:44:34 +01:00
Jacek Kałużny
7fde0b4513
Add files via upload 2023-10-30 09:43:54 +01:00
IgnBys
0f38d2c2c2 Edited TaskAO2 with - 2023-10-30 09:43:42 +01:00
IgnBys
fad6f557cb TaskAO2 was ended 2023-10-29 10:11:56 +01:00
IgnBys
c91aa0f040 TaskAO4 was ended 2023-10-29 08:51:31 +01:00
IgnBys
9c9b65d1ee Merge branch 'master' of https://git.wmi.amu.edu.pl/s473579/jfz-2023-s473579 2023-10-28 23:55:37 +02:00
IgnBys
249f02be9c Edited file names 2023-10-28 23:55:09 +02:00
79fa940338 delete unnecessary file 2023-10-28 23:18:31 +02:00
419 changed files with 1495861 additions and 458 deletions

122
.idea/workspace.xml Normal file
View File

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="72cf1fbd-40b3-47aa-ad24-b4e28ca48019" name="Changes" comment="">
<change afterPath="$PROJECT_DIR$/.idea/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/inspectionProfiles/profiles_settings.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/jezykiformalne.iml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/misc.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/modules.xml" afterDir="false" />
<change afterPath="$PROJECT_DIR$/.idea/vcs.xml" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MarkdownSettingsMigration">
<option name="stateVersion" value="1" />
</component>
<component name="ProjectId" id="2XTqxj3Jb6nsJrXb6dR6Eezc5p6" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
"WebServerToolWindowFactoryState": "false",
"last_opened_file_path": "J:/PycharmProjects/JezykiFormalne",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager" selected="Python.main">
<configuration name="main" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jezykiformalne" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/TaskC00" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/TaskC00/main.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<configuration name="run" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
<module name="jezykiformalne" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/TaskB00" />
<option name="IS_MODULE_SDK" value="true" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/TaskB00/run.py" />
<option name="PARAMETERS" value="" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Python.main" />
<item itemvalue="Python.run" />
</list>
</recent_temporary>
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="72cf1fbd-40b3-47aa-ad24-b4e28ca48019" name="Changes" comment="" />
<created>1698663666324</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1698663666324</updated>
<workItem from="1698663667983" duration="3669000" />
<workItem from="1698667393874" duration="591000" />
<workItem from="1698875504210" duration="801000" />
<workItem from="1698876438874" duration="278000" />
<workItem from="1700049092114" duration="71000" />
<workItem from="1700049195784" duration="1534000" />
<workItem from="1701083054912" duration="676000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
<component name="com.intellij.coverage.CoverageDataManagerImpl">
<SUITE FILE_PATH="coverage/jezykiformalne$main.coverage" NAME="main Coverage Results" MODIFIED="1700050514289" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/TaskC00" />
<SUITE FILE_PATH="coverage/jezykiformalne$run.coverage" NAME="run Coverage Results" MODIFIED="1698667882969" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="true" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/TaskB00" />
</component>
</project>

349
README.md
View File

@ -1,6 +1,11 @@
## Zajęcia 1
Copyright AMU Poznan
Made by multiple people
### Informacje na temat przedmiotu
Prowadzący: Jacek Kałużny
@ -18,347 +23,3 @@ W ten sposób będziemy aktualizować zadania co zajęcia.
Zadania robimy do końca soboty poprzedzającej zajęcia
Rozwiązanie zapisujemy w pliku run.py
## Zajęcia 2 Wyrażenia regularne
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(answer.start())
print(answer.end())
print(answer.group())
answer = re.search('na','kabanos')
print(answer)
type(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)
Do nauki lepiej użyć pythona w wersji interaktywnej, a najlepiej ipython.
```
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')
```
#### 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)
```
#### RE.COMPILE
## zajęcia 6
instalacja https://pypi.org/project/google-re2/
### DFA i NDFA
```
import re2 as re
n = 50
regexp = "a?"*n+"a"*n
s = "a"*n
re.match(regexp, s)
```
```
re.match(r"(\d)abc\1", "3abc3") # re2 nie obsługuje backreferencji
```
re2 max memory - podniesienie limitu
time # mierzenie czasu działania
gdyby ktoś chciał poczytać więcej:
https://swtch.com/~rsc/regexp/regexp1.html
### UTF-8
```
c = ""
ord(c)
chr(8459)
8* 16**2 + 0 * 16**(1) + 0*16**(0)
15*16**3 + 15* 16**2 + 15 * 16**(1) + 15*16**(0)
```
```
xxd -b file
xxd file
```
termin oddawania zadań - 15. listopada
## Zajęcia 7
https://www.openfst.org/twiki/bin/view/GRM/Thrax
https://www.cs.jhu.edu/~jason/465/hw-ofst/hw-ofst.pdf
Wszystkie zadania proszę robić na wzór `TaskH00`. Proszę umieszczać gramatykę w pliku `grammar.grm` oraz
opisywać finalną regułę nazwą `FinalRule`.
## KOLOKWIUM
Operatory, obowiązujące na kolokwium
====================================
* kwantyfikatory `-` `*` `+` `?` `{n}` `{n,}` `{n, m}`
* alternatywa — `|`
* klasy znaków — `[...]`
* zanegowane klasy znaków — `[^...]`
* dowolny znak — `.`
* unieważnianie znaków specjalnych — \
* operatory zakotwiczające — `^` `$`
Na kolokwium do każdego z 4 pytań będą 3 podpunkty. Na każdy podpunkt odpowiadamy TAK/NIE. Czas trwania to 15 minut.
- zawsze daszek i dolar
- nie bierzemy pod uwagę capturing (jeżeli są pytania o równoważne)
- proponuję wydrukować cały test w wersji bez opdowiedzi i sprawdzać
Do zaliczenia należy zdobyć conajmniej 10 punktów.

View File

@ -1,44 +0,0 @@
import re
def openFile(fileName,hamletArray = ['H','a', 'm', 'l', 'e', 't'], hamletFullWord = r'Hamlet'):
with open(fileName, "r", encoding="utf-8") as file:
file_contents = file.read()
repCounter = 0
line = ''
counter = 0
checkWord = ''
index = 0
length = len(file_contents)
while index < length:
character = file_contents[index]
line += character
if len(checkWord) < len(hamletFullWord):
if re.match(hamletArray[counter], character):
checkWord+=character
counter += 1
else:
checkWord = ''
counter = 0
if character=='\n':
if checkWord=='Hamlet':
print(line)
line = ''
counter = 0
checkWord = ''
index+=1
#
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('shakespeare.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('shakespeare.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,36 +0,0 @@
def openFile(fileName,piesArray = ['[Pp ]', 'i', 'e', 's', '[ \t\n.,;!?]']):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
repCounter = 0
counter = 0
checkWord =[]
for i in row:
if i in piesArray[counter]:
if i != ' ' or counter != 0:
checkWord+=i
counter+=1
if len(checkWord) >= 5:
sum = 0
for z in checkWord:
if z in piesArray[sum]:
sum +=1
if sum ==4:
checkWord = []
counter = 0
repCounter += 1 # if in one row more than one Hamlet it will write the row only once
if repCounter == 1:
print(row.strip())
else:
checkWord = []
counter = 0
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,31 +0,0 @@
import re
def openFile(fileName,piesArray1 = [' ', 'P', 'p', '('],
piesArray2 = ['i', 'e', 's'],
piesArray3 = ['\t', '\n', '.', ',', ';', '!', '?', ')']):
with open(fileName, "r", encoding="utf-8") as file:
file_contents = file.read()
for row in file:
piesArrayCounter = 0
repCounter = 0
counter = 0
checkWord = ''
for character in row:
if character == ' ':
checkWord+=character
if counter == 0 and checkWord == ' ':
if (character == 'P' or character == 'p'):
counter +=1
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('shakespeare.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('shakespeare.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

67
TaskA02/run.py Normal file
View File

@ -0,0 +1,67 @@
def checkFirstSymbol(character):
if character == 'P' or character == 'p' or character == ' ':
return character
else:
return None
def checkLastSymbol(character):
if (character == '\t'
or character == '\n'
or character == '.'
or character == ','
or character == ';'
or character == '!'
or character == ' '
or character == '?'
or character == '-'
or character == ')'):
return character
else:
return None
def openFile(fileName):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
lastWordSymbol = ''
counter = 0
checkWord = []
for i in row:
if lastWordSymbol == '' or lastWordSymbol == ' ':
if i == 'P' or i=='p':
checkWord+=i
lastWordSymbol = i
elif lastWordSymbol == checkFirstSymbol(lastWordSymbol):
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 'i' and i=='e':
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 'e' and i == 's':
checkWord += i
lastWordSymbol = i
elif lastWordSymbol == 's' and i == checkLastSymbol(i):
checkWord += i
lastWordSymbol = i
else:
checkWord=[]
lastWordSymbol=''
if (len(checkWord)>=5 and checkWord[0]==checkFirstSymbol(checkWord[0])
and checkWord[1] == 'i'
and checkWord[2] == 'e'
and checkWord[3] == 's'
and checkWord[4] == checkLastSymbol(checkWord[4])):
print(row, end ='')
break
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,2 +0,0 @@
str = r'[Pp ]ies '
print(len(str))

52
TaskA04/run.py Normal file
View File

@ -0,0 +1,52 @@
import sys
def checkNumber(letter):
if (letter == '0'
or letter == '1'
or letter == '2'
or letter == '3'
or letter == '4'
or letter == '5'
or letter == '6'
or letter == '7'
or letter == '8'
or letter == '9'):
return letter
else:
return None
def openFile(fileName):
with open(fileName, "r", encoding="utf-8") as file:
for row in file:
lastCharacter = ''
checkWord =''
allLine = ''
for letter in row:
if checkWord != '':
if letter == checkNumber(letter):
checkWord += letter
else:
allLine += checkWord
allLine += ' '
checkWord = ''
else:
if letter == checkNumber(letter):
checkWord += letter
if letter == '\n':
if allLine != '':
print(allLine)
allLine = ''
print('---------------------SHAKESPEARE.EXP--------------------------------------')
openFile('polish_wiki_excerpt.exp')
print('----------------------SHAKESPEARE.EXP-----------------------------------')
openFile('polish_wiki_excerpt.in')
print('------------------------SIMPLE.IN------------------------------------')
openFile('simple.in')
print('-----------------------SIMPLE.EXP--------------------------------------')
openFile('simple.exp')

View File

@ -1,5 +1,5 @@
cd jfz34234 34 dfd gfd 5
34535
fsdflskfjsdflk
fsdflskf3jsdf3lk
fsdkfj sdf34fdfd
Firma powstała w 1992 r., z połączenia Authorware, Inc. (twórców pakietu Authorware) i MacroMind-Paracomp (producenta Macromind Director). W 1999 r. Macromedia zakupiła firmę Allaire i jej bi

View File

@ -0,0 +1,2 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\test1.in .\test1.out

8
TaskB00/description.txt Normal file
View File

@ -0,0 +1,8 @@
Read a description of a 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: ./run.py fsa_description.arg < test1.in > test1.out

View File

@ -0,0 +1,16 @@
0 1 x
1 2 y
2 3 z
0 4 y
0 4 z
1 4 x
1 4 z
2 4 x
2 4 y
3 4 x
3 4 y
3 4 z
4 4 x
4 4 y
4 4 z
3

34
TaskB00/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split('\t')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test1.in'
# output_file = 'test1.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='3':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

9
TaskB00/test1.exp Normal file
View File

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

9
TaskB00/test1.in Normal file
View File

@ -0,0 +1,9 @@
xxyz
xyz
xy
zz
xxy
yzx
x
xyzz

9
TaskB00/test1.out Normal file
View File

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

View File

@ -0,0 +1,2 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\test.in .\test.out

10
TaskB01/description.txt Normal file
View File

@ -0,0 +1,10 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string starts with "01" and ends with "01.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -0,0 +1,12 @@
0 1 0
0 3 1
3 3 0
3 3 1
1 3 0
1 2 1
2 4 1
4 4 1
4 5 0
5 5 0
2 5 0
5 2 1

34
TaskB01/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='2':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

14
TaskB01/test.exp Normal file
View File

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

14
TaskB01/test.in Normal file
View File

@ -0,0 +1,14 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

14
TaskB01/test.out Normal file
View File

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

9
TaskB02/description.txt Normal file
View File

@ -0,0 +1,9 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string starts with "10" and ends with "10.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -0,0 +1,12 @@
0 1 1
0 3 0
3 3 1
3 3 0
1 3 1
1 2 0
2 4 0
4 4 0
4 5 1
5 5 1
2 5 1
5 2 0

34
TaskB02/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='2':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

14
TaskB02/test.exp Normal file
View File

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

14
TaskB02/test.in Normal file
View File

@ -0,0 +1,14 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

14
TaskB02/test.out Normal file
View File

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

11
TaskB03/description.txt Normal file
View File

@ -0,0 +1,11 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string contains "0"
even number of times.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -0,0 +1,4 @@
0 1 0
1 1 1
1 0 0
0 0 1

34
TaskB03/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='0':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

14
TaskB03/test.exp Normal file
View File

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

14
TaskB03/test.in Normal file
View File

@ -0,0 +1,14 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

14
TaskB03/test.out Normal file
View File

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

11
TaskB04/description.txt Normal file
View File

@ -0,0 +1,11 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskE00.
Create your own FSA description to check whether the string contains "0"
odd number of times.
Save it to fsa_description.arg file.
The alphabet is "0", "1".
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

@ -0,0 +1,4 @@
0 1 0
1 1 1
1 0 0
0 0 1

34
TaskB04/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='1':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

14
TaskB04/test.exp Normal file
View File

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

14
TaskB04/test.in Normal file
View File

@ -0,0 +1,14 @@
01
10
0101
1010
011101
101010
100010
0100001
00110
0000
10101
0
1

14
TaskB04/test.out Normal file
View File

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

View File

@ -0,0 +1,4 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\simple.in .\simple.out
or
python .\run.py .\fsa_description.arg .\polish_wiki_excerpt_only_digits.in .\polish_wiki_excerpt_only_digits.out

10
TaskB05/description.txt Normal file
View File

@ -0,0 +1,10 @@
Use a deterministic finite-state automaton (FSA) engine from the TaskB00.
Create your own FSA description to check whether the line contains string '19DD', where D is a digit.
Save it to fsa_description.arg file.
FSA alphabet is '0123456789x'.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

View File

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

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

34
TaskB05/run.py Normal file
View File

@ -0,0 +1,34 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='4':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

6
TaskB05/simple.exp Normal file
View File

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

6
TaskB05/simple.in Normal file
View File

@ -0,0 +1,6 @@
3214545443
1910
19
xxx2190x
xxx21905x
1905x54545

6
TaskB05/simple.out Normal file
View File

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

View File

@ -0,0 +1,4 @@
If you use windows please write this command in terminal:
python .\run.py .\fsa_description.arg .\simple.in .\simple.out
or
python .\run.py .\fsa_description.arg .\shakespeare_ascii_lower.in .\shakespeare_ascii_lower.out

9
TaskB06/description.txt Normal file
View File

@ -0,0 +1,9 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "hamlet" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

189
TaskB06/fsa_description.arg Normal file
View File

@ -0,0 +1,189 @@
0 1 h
1 2 a
2 3 m
3 4 l
4 5 e
5 6 t
0 0 a
0 0 b
0 0 c
0 0 d
0 0 e
0 0 f
0 0 g
0 0 i
0 0 j
0 0 k
0 0 l
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06/run.py Normal file
View File

@ -0,0 +1,37 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
used_table = 'fsa_description.arg'
input_file = 'simple.in'
output_file = 'simple.out'
# used_table = sys.argv[1]
# input_file = sys.argv[2]
# output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='6':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

3
TaskB06/simple.exp Normal file
View File

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

3
TaskB06/simple.in Normal file
View File

@ -0,0 +1,3 @@
haml
hamlet
aaahamletbbb

3
TaskB06/simple.out Normal file
View File

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

10
TaskB07/description.txt Normal file
View File

@ -0,0 +1,10 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "ophelia" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

216
TaskB07/fsa_description.arg Normal file
View File

@ -0,0 +1,216 @@
0 1 o
1 2 p
2 3 h
3 4 e
4 5 l
5 6 i
6 7 a
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 0 m
0 0 n
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 0 a
1 0 h
1 0 b
1 0 c
1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
7 7 v
7 7 w
7 7 x
7 7 y
7 7 z
7 7

37
TaskB07/run.py Normal file
View File

@ -0,0 +1,37 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='7':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

3
TaskB07/simple.exp Normal file
View File

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

3
TaskB07/simple.in Normal file
View File

@ -0,0 +1,3 @@
oph
ophelia
xfdfdopheliafff

3
TaskB07/simple.out Normal file
View File

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

10
TaskB08/description.txt Normal file
View File

@ -0,0 +1,10 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "juliet" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

189
TaskB08/fsa_description.arg Normal file
View File

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

37
TaskB08/run.py Normal file
View File

@ -0,0 +1,37 @@
import sys
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='6':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

3
TaskB08/simple.exp Normal file
View File

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

3
TaskB08/simple.in Normal file
View File

@ -0,0 +1,3 @@
juli
juliet
dgfdgjulietaaa

3
TaskB08/simple.out Normal file
View File

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

10
TaskB09/description.txt Normal file
View File

@ -0,0 +1,10 @@
Use a deterministic finite-state automaton (FSA) engine from the previous task.
Create your own FSA description to check whether the word "macbeth" is in the given line.
Save it to fsa_description.arg file.
FSA alphabet is 'abcdefghijklmnopqrstuvwxyz '.
Read strings from the standard input.
If a string is accepted by the
automaton, write YES, otherwise- write NO.

216
TaskB09/fsa_description.arg Normal file
View File

@ -0,0 +1,216 @@
0 1 m
1 2 a
2 3 c
3 4 b
4 5 e
5 6 t
6 7 h
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 0 n
0 0 0
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 0
1 0 h
1 0 b
1 0 c
1 0 d
1 0 e
1 0 f
1 0 g
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 w
1 0 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position(position, character):
with open(used_table, 'r') as readed_used_table:
for row_used_table in readed_used_table:
line = row_used_table.strip().split(' ')
length = len(line)
if length == 2:
line.append(' ')
if position == line[0] and character == line[2]:
return True,line[1]
# used_table = 'fsa_description.arg'
# input_file = 'test.in'
# output_file = 'test.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
result = False
next_position = None
position = '0'
for character in row_input_file:
if character =='\n':
if position=='7':
write_answer('YES')
break
else:
write_answer('NO')
break
result, next_position = find_next_position(position,character)
if result == True:
position = next_position

File diff suppressed because it is too large Load Diff

3
TaskB09/simple.exp Normal file
View File

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

3
TaskB09/simple.in Normal file
View File

@ -0,0 +1,3 @@
macb
macbeth
xadadamacbethrff

3
TaskB09/simple.out Normal file
View File

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

12
TaskC00/description.txt Normal file
View File

@ -0,0 +1,12 @@
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.

4041
TaskC00/long.arg Normal file

File diff suppressed because it is too large Load Diff

7
TaskC00/long.exp Normal file
View File

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

7
TaskC00/long.in Normal file
View File

@ -0,0 +1,7 @@
aaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa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aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
xyz
aba
a

7
TaskC00/long.out Normal file
View File

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

59
TaskC00/run.py Normal file
View File

@ -0,0 +1,59 @@
import sys
sys.setrecursionlimit(5000)
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def line_checking(row, position):
stack = [(row, position)]
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
return False
def find_next_position(position, character):
with open(used_table, 'r') as readed_used_table:
take_all_possible_positions = []
for row_used_table in readed_used_table:
line = row_used_table.strip().split('\t')
if len(line) != 1:
if position == line[0] and character == line[2]:
take_all_possible_positions.append(line[1])
return take_all_possible_positions
def what_is_the_ended_positions():
array = []
with open(used_table, 'r') as file:
for row in file:
line = row.strip().split('\t')
if len(line) == 1:
array += line
return array
# used_table = 'testnfa.arg'
# input_file = 'testnfa.in'
# output_file = 'testnfa.out'
used_table = sys.argv[1]
input_file = sys.argv[2]
output_file = sys.argv[3]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
if line_checking(row_input_file, '0'):
write_answer('YES')
else:
write_answer('NO')

16
TaskC00/test1.arg Normal file
View File

@ -0,0 +1,16 @@
0 1 x
1 2 y
2 3 z
0 4 y
0 4 z
1 4 x
1 4 z
2 4 x
2 4 y
3 4 x
3 4 y
3 4 z
4 4 x
4 4 y
4 4 z
3

9
TaskC00/test1.exp Normal file
View File

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

9
TaskC00/test1.in Normal file
View File

@ -0,0 +1,9 @@
xxyz
xyz
xy
zz
xxy
yzx
x
xyzz

9
TaskC00/test1.out Normal file
View File

@ -0,0 +1,9 @@
NO
YES
NO
NO
NO
NO
NO
NO
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

11
TaskC01/description.txt Normal file
View File

@ -0,0 +1,11 @@
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.

62
TaskC01/run.py Normal file
View File

@ -0,0 +1,62 @@
import sys
sys.setrecursionlimit(5000)
arg = [['0','0','a'],
['0', '0' ,'b'],
['0' ,'0' ,'c'],
['0', '1', 'b'],
['1', '2', 'a'],
['1', '2', 'b'],
['1', '2','c'],
'2']
def write_answer(answer):
with open(output_file, 'a') as file:
file.write(answer+'\n')
def line_checking(row, position):
stack = [(row, position)]
while stack:
help_row, help_position = stack.pop()
if help_row == '\n':
if help_position in what_is_the_ended_positions():
return True
else:
return False
next_character_array = find_next_position(help_position, help_row[0])
if next_character_array:
for element_in_next_position_array in next_character_array:
stack.append((help_row[1:], element_in_next_position_array))
return False
def find_next_position(position, character):
take_all_possible_positions = []
for row_used_table in arg:
if len(row_used_table) != 1:
if position == row_used_table[0] and character == row_used_table[2]:
take_all_possible_positions.append(row_used_table[1])
return take_all_possible_positions
def what_is_the_ended_positions():
array = []
for row in arg:
if len(row) == 1:
array += row
return array
# used_table = 'test.arg'
# input_file = 'test.in'
# output_file = 'test.out'
# used_table = sys.argv[1]
input_file = sys.argv[1]
output_file = sys.argv[2]
with open(output_file, 'w') as readed_output_file:
with open(input_file, 'r') as readed_input_file:
for row_input_file in readed_input_file:
if line_checking(row_input_file, '0'):
write_answer('YES')
else:
write_answer('NO')

8
TaskC01/test.arg Normal file
View File

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

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