Zadania 1-4

This commit is contained in:
Wojtek 2023-10-29 22:02:40 +01:00
parent 08e1fae56b
commit 7a8ad949bc
26 changed files with 240967 additions and 1 deletions

365
README.md
View File

@ -1 +1,364 @@
test2
## Zajęcia 1
### Informacje na temat przedmiotu
Prowadzący: Jacek Kałużny
mail: duszekjk@gmail.com
#### Wysyłanie zadań
Proszę stworzyć prywatne repozytorium na https://git.wmi.amu.edu.pl/ o nazwie jfz-2023-sNRINDEKSU oraz dać
prawa do odczytu dla prowadzącego zajęcia. W NRINDEKSU proszę wpisać swój nr indeksu, np. jfz-2023-s123456.
Następnie w swoim repozytorium proszę spullować niniejsze repozytorium: `git pull git@github.com:duszekjk/jezykiformalne.git`
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.

5
TaskA01/description.txt Normal file
View File

@ -0,0 +1,5 @@
Write a program to find lines containing the word "Hamlet".
Do not use regular expressions, just the simplest capabilities
of a programming language.
POINTS: 1

19
TaskA01/run.py Normal file
View File

@ -0,0 +1,19 @@
def findHamlet(filename):
target = "Hamlet"
target_length = len(target)
with open(filename, 'r', encoding="utf-8") as file:
line_number = 1
for line in file:
for i in range(len(line) - target_length):
match=True
for j in range(target_length):
if line[i+j] != target[j]:
match=False
break
if match:
print(f"Line {line_number}")
break
line_number += 1
findHamlet('TaskA01/simple.in')

106
TaskA01/shakespeare.exp Normal file
View File

@ -0,0 +1,106 @@
CLAUDIUS, King of Denmark, Hamlets uncle.
The GHOST of the late king, Hamlets father.
GERTRUDE, the Queen, Hamlets mother, now wife of Claudius.
HORATIO, Friend to Hamlet.
Dard to the combat; in which our valiant Hamlet,
His fell to Hamlet. Now, sir, young Fortinbras,
Unto young Hamlet; for upon my life,
Enter Claudius King of Denmark, Gertrude the Queen, Hamlet, Polonius,
Though yet of Hamlet our dear brothers death
But now, my cousin Hamlet, and my son—
Good Hamlet, cast thy nighted colour off,
Tis sweet and commendable in your nature, Hamlet,
Let not thy mother lose her prayers, Hamlet.
This gentle and unforcd accord of Hamlet
[_Exeunt all but Hamlet._]
For Hamlet, and the trifling of his favour,
So please you, something touching the Lord Hamlet.
Than a command to parley. For Lord Hamlet,
As to give words or talk with the Lord Hamlet.
Enter Hamlet, Horatio and Marcellus.
That I will speak to thee. Ill call thee Hamlet,
[_Ghost beckons Hamlet._]
[_Exeunt Ghost and Hamlet._]
Enter Ghost and Hamlet.
Wouldst thou not stir in this. Now, Hamlet, hear.
O Hamlet, what a falling off was there,
Adieu, adieu, adieu. Hamlet, remember me.
[_Within._] Lord Hamlet.
And what so poor a man as Hamlet is
Lord Hamlet, with his doublet all unbracd,
Of Hamlets transformation; so I call it,
And bring these gentlemen where Hamlet is.
The very cause of Hamlets lunacy.
Came this from Hamlet to her?
Lord Hamlet is a prince, out of thy star.
Enter Hamlet, reading.
How does my good Lord Hamlet?
You go to seek the Lord Hamlet; there he is.
For we have closely sent for Hamlet hither,
Of Hamlets wildness: so shall I hope your virtues
Enter Hamlet.
You need not tell us what Lord Hamlet said,
Enter Hamlet and certain Players.
How fares our cousin Hamlet?
I have nothing with this answer, Hamlet; these words are not mine.
Come hither, my dear Hamlet, sit by me.
[_Exeunt all but Hamlet and Horatio._]
[_Exeunt all but Hamlet._]
Enter Hamlet.
Enter Hamlet.
Hamlet, thou hast thy father much offended.
Why, how now, Hamlet?
O Hamlet, speak no more.
No more, sweet Hamlet.
Speak to her, Hamlet.
O Hamlet, thou hast cleft my heart in twain.
[_Exit Hamlet dragging out Polonius._]
What, Gertrude? How does Hamlet?
Hamlet in madness hath Polonius slain,
Enter Hamlet.
[_Within._] Hamlet! Lord Hamlet!
What noise? Who calls on Hamlet? O, here they come.
Enter Hamlet and Guildenstern.
Now, Hamlet, wheres Polonius?
Hamlet, this deed, for thine especial safety,—
Ay, Hamlet.
Thy loving father, Hamlet.
The present death of Hamlet. Do it, England;
Enter Hamlet, Rosencrantz, Guildenstern &c.
[_Exeunt all but Hamlet._]
I should be greeted, if not from Lord Hamlet.
Letters, my lord, from Hamlet.
From Hamlet! Who brought them?
Tis Hamlets character. Naked!
And that in Hamlets hearing, for a quality
Did Hamlet so envenom with his envy
Hamlet comes back: what would you undertake
Hamlet returnd shall know you are come home:
Enter Hamlet and Horatio, at a distance.
Hamlet oercame Fortinbras.
that young Hamlet was born,—he that is mad, and sent into England.
I hopd thou shouldst have been my Hamlets wife;
Hamlet the Dane.
Hamlet! Hamlet!
Enter Hamlet and Horatio.
[_Hamlet moves him to put on his hat._]
Come, Hamlet, come, and take this hand from me.
[_The King puts Laertess hand into Hamlets._]
Wast Hamlet wrongd Laertes? Never Hamlet.
If Hamlet from himself be taen away,
Then Hamlet does it not, Hamlet denies it.
Hamlet is of the faction that is wrongd;
His madness is poor Hamlets enemy.
Give them the foils, young Osric. Cousin Hamlet,
If Hamlet give the first or second hit,
The King shall drink to Hamlets better breath,
Now the King drinks to Hamlet. Come, begin.
Stay, give me drink. Hamlet, this pearl is thine;
Here, Hamlet, take my napkin, rub thy brows.
The Queen carouses to thy fortune, Hamlet.
[_Laertes wounds Hamlet; then, in scuffling, they change rapiers, and
Hamlet wounds Laertes._]
No, no, the drink, the drink! O my dear Hamlet!
It is here, Hamlet. Hamlet, thou art slain.
Exchange forgiveness with me, noble Hamlet.
Bear Hamlet like a soldier to the stage,

169442
TaskA01/shakespeare.in Normal file

File diff suppressed because it is too large Load Diff

2
TaskA01/simple.exp Normal file
View File

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

3
TaskA01/simple.in Normal file
View File

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

7
TaskA02/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 not use regular expressions, just the simplest capabilities
of a programming language.
POINTS: 1

View File

@ -0,0 +1,13 @@
Pies ten pochodzi z południowych Chin, z terenów prowincji Guangdong. Został rozpropagowany i hodowany w celach wystawowych przez hodowców w USA. Nazwa psa, pochodząca z chińskiego "shā pí" (沙皮), oznacza dosłownie "piaszczysta skóra".
Chart polski polska rasa psa myśliwskiego, znana prawdopodobnie od czasów Galla Anonima, zaliczana do grupy chartów. Dawniej użytkowana była przede wszystkim do polowań, obecnie jako pies reprezentacyjny.
Smukły pies o wąskim pysku. Chart polski jest wyraźnie mocniejszy i nie tak finezyjny w kształtach jak inne charty. Jest najwyższą z polskich ras.
Chart polski to pies silny, wytrzymały, o dobrze zbalansowanym ciele i proporcjach (wpisany jest w prostokąt oparty na dłuższym boku) pozwalających nie tylko na szybki galop, ale i na pokonywanie dużych odległości wyciągniętym kłusem. Jest psem o okrywie włosowej dobrze chroniącej go przed zimnem, wilgocią i wiatrem.
Pies wymagający sporej dawki codziennego ruchu, stąd jest idealnym towarzyszem dla ludzi uprawiających jeździectwo lub jogging.
W filmie występuje pies rasy landseer.
Bohaterami anime jest grupa łowców nagród, podróżująca statkiem kosmicznym o nazwie "Bebop": Spike Spiegel, Faye Valentine, Jet Black, haker Ed oraz genetycznie zmodyfikowany pies Ein.
Tytułowym głównym bohaterem serii jest Lucky Luke - kowboj, najszybszy rewolwerowiec na Dzikim Zachodzie i najgorszy koszmar braci Dalton. Zawsze, gdy planują oni skok na bank lub inne przestępstwo, dzielny stróż prawa staje im na drodze. W jego przygodach towarzyszą mu inteligentny koń Jolly Jumper i pies Bzik (we francuskojęzycznym oryginale: "Rantanplan").
Serial w krzywym zwierciadle przedstawia życie typowej amerykańskiej rodziny. Jej głową i jedynym żywicielem jest wiecznie sfrustrowany sprzedawca butów, Al Bundy. Kocha swojego starego dodge'a, wolny czas spędza siedząc na kanapie, oglądając telewizję i pijąc piwo lub na posiedzeniach w toalecie. Jego małżonką jest Peggy, która całymi dniami przesiaduje przed telewizorem, oglądając "The Oprah Winfrey Show", i The Phil Donahue Show zajadając się popcornem i czekoladkami, paląc przy tym papierosa za papierosem. O jej podejściu do typowo domowych zajęć świadczą zadawane przez nią pytania, np. o odkurzacz "Jak się nazywa to coś, co ciągniesz po dywanie, a ono buczy?" Tytułowymi dziećmi są nastoletni Bud oraz Kelly, którzy nie przepadają za sobą i nie przepuszczą żadnej okazji, aby sobie dokuczyć czy donieść na siebie. Kelly i Bud dojrzewają w trakcie trwania serialu, przez co trochę się zmieniają: Bud z wrednego kilkunastolatka przeistacza się w nastoletniego macho, którego nie chce żadna dziewczyna, a Kelly z każdą serią staje się coraz mniej inteligentna. Wiecznie niedocenianym członkiem rodziny jest pies Buck, który jednak żyje swoim życiem i sam troszczy się o siebie. W trakcie wszystkich dziesięciu lat trwania serialu Bundym towarzyszy dwójka sąsiadów: Marcy, najpierw ze swoim pierwszym mężem, Steve'em Rhoadesem, a następnie z Jeffersonem d'Arcym. Marcy lubi przebywać z Peggy, jest za to na bakier z Alem, natomiast Al utrzymuje dobre stosunki z mężami Marcy, szczególnie Jeffersonem Steve raczej nie darzył Bundych tak bezwzględną sympatią.
Buck (prawdziwe imię Michael; trener Steven Ritt) to pies rodziny Bundych, Briard. Głosu użycza mu Kevin Curran, a w odcinkach specjalnych Cheech Marin. Zdechł w wieku dwunastu lat (w 1996 roku Michael przeszedł na emeryturę, zdechł dziewięć miesięcy po tym, jak Bucka uśmiercono w serialu).
Lucky to drugi pies rodziny Bundych, spaniel, reinkarnacja Bucka.
20 stycznia 1974 r. o godz. 10.40 w Dolinie Mięguszowieckiej wydarzyła się największa jak do owej pory katastrofa lawinowa w Tatrach. Żlebem spod Przełęczy nad Skokiem w Grani Baszt zeszła potężna lawina, która przewaliła się przez Mięguszowiecki Potok i wdarła 140 m na przeciwległy stok, wspinając się na niego z rozpędu aż 44 m w górę. Na stoku tym, na śnieżnym pólku trenowali z instruktorem uczestnicy kursu narciarskiego ze słowackiego Technikum Budowlanego. Lawina przysypała 24 z nich. Dzięki błyskawicznej akcji ratunkowej (było to tylko 400 m od schroniska nad Popradzkim Stawem) udało się odgrzebać spod śniegu 11 płycej przywalonych. W ciągu następnych godzin i kilku dni liczne zespoły ratunkowe (z pomocą przyszło również wojsko) odgrzebały ciała 10 uczestników kursu; wśród nich nauczyciela z 12-letnim synem. Pies wskazał miejsce, gdzie po 5 godzinach od zejścia lawiny wydobyto żywego 18-latka przywalonego metrową warstwą śniegu. Ciała dwóch uczniów udało się znaleźć dopiero wiosną po stopieniu się śniegu.
Początkowo Morris wykorzystał w swoich komiksach historycznych braci Daltonów Grat, Bill i Emmett, których przedstawił jako bardzo groźnych i inteligentnych przestępców. Niestety po pierwszym spotkaniu z Lucky Luke, zostali aresztowani i skazani w więzieniu na śmierć. Morris żałował potem swojej decyzji i wraz z Gościnnym wprowadził na ich miejsce, czwórkę kuzynów (także) Daltonów Joe, Williama, Jacka i Averelle, którzy byli przeciwieństwem swoich kuzynów. Wiecznie pechowi, gamoniowaci i niezbyt inteligentni. Wkrótce stali się oni najpopularniejszymi postaciami w serii, zaraz po samym Lucky Luke i z czasem dołączył do nich pies Rantanplan. Doczekali się także solowego filmu dystrybuowanego w Polsce pt. "Lucky Luke" (oryg. "Les Dalton").

50000
TaskA02/polish_wiki_excerpt.in Normal file

File diff suppressed because one or more lines are too long

24
TaskA02/run.py Normal file
View File

@ -0,0 +1,24 @@
def findPies(filename):
target = "pies"
target_length = len(target)
with open(filename, 'r', encoding="utf-8") as file:
line_number = 1
for line in file:
for i in range(len(line) - target_length + 1):
match = (
(line[i] == 'p' or line[i] == 'P') and
(line[i + 1] == 'i' or line[i + 1] == 'I') and
(line[i + 2] == 'e' or line[i + 2] == 'E') and
(line[i + 3] == 's' or line[i + 3] == 'S')
)
start = i == 0 or line[i - 1] == ' '
end = i + target_length == len(line) or line[i + target_length] == ' '
if match and (start or end):
print(f"Line {line_number}")
break
line_number += 1
findPies('TaskA02/simple.in')

3
TaskA02/simple.exp Normal file
View File

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

5
TaskA02/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

6
TaskA03/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 not use regular expressions, just the simplest capabilities
of a programming language.
POINTS: 2

File diff suppressed because one or more lines are too long

View File

19
TaskA03/run.py Normal file
View File

@ -0,0 +1,19 @@
def findDate(filename):
target = "pies"
target_length = len(target)
with open(filename, 'r', encoding="utf-8") as file:
line_number = 1
for line in file:
if len(line) >= 7:
for i in range(len(line) - 6):
if line[i] == '1' and line[i+1] == '9':
char3 = line[i + 2] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
char4 = line[i + 3] in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
if char3 and char4:
if line[i+4] == ' ' and line[i+5] == 'r' and line[i+6] == '.':
print(f"Line {line_number}")
break
line_number += 1
findDate('TaskA03/simple.in')

3
TaskA03/simple.exp Normal file
View File

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

5
TaskA03/simple.in Normal file
View File

@ -0,0 +1,5 @@
Kiedyś był 1934 r.
Kiedyś był 1934 r.fsdfsdfsdf
Kiedyś był 1935 rok
1934 r. to jakaś data
1934 to też jakaś data

6
TaskA04/description.txt Normal file
View File

@ -0,0 +1,6 @@
Write a program to find all maximum substrings of digits.
Return only these substrings separated by spaces in their order.
Do not use regular expressions, just the simplest capabilities
of a programming language.
POINTS: 3

File diff suppressed because it is too large Load Diff

View File

30
TaskA04/run.py Normal file
View File

@ -0,0 +1,30 @@
def findNumber(filename):
substrings = []
with open(filename, 'r', encoding="utf-8") as file:
line = 1
last_number = -1
flag = 0
for line in file:
substring = ''
for i in line:
if i == ' ' or i == '\n':
flag = 0
if i in ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']:
if int(i) >= last_number:
if flag == 0:
substring += i
last_number = int(i)
else:
last_number = -1
substring = ''
flag = 1
#break
else:
if len(substring) >= 1:
substrings.append(substring)
substring = ''
last_number = -1
flag = 0
print(substrings)
findNumber('TaskA04/test.txt')

4
TaskA04/simple.exp Normal file
View File

@ -0,0 +1,4 @@
34234 34 5
34535
34
1992 1999

5
TaskA04/simple.in Normal file
View File

@ -0,0 +1,5 @@
34234 34 dfd gfd 5
34535
fsdflskfjsdflk
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

6
TaskA04/test.txt Normal file
View File

@ -0,0 +1,6 @@
12
54321 68 89
21
31111
2888
3344