zad 1 i 2
This commit is contained in:
parent
0c23da0e15
commit
93abfbbd8e
43
TaskA01/run.py
Normal file
43
TaskA01/run.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
NUMBER_OF_INVOICES = 10
|
||||||
|
DIR = os.path.dirname(__file__)
|
||||||
|
HAMLET = "Hamlet"
|
||||||
|
|
||||||
|
|
||||||
|
def join_path(filename: str) -> str:
|
||||||
|
return os.path.join(DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
|
with open(join_path("shakespeare.in"), "r", newline="", encoding="utf8") as file:
|
||||||
|
text = file.readlines()
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
found = True
|
||||||
|
hamlet_array_slow = []
|
||||||
|
for ind, line in enumerate(text):
|
||||||
|
for i in range(len(line)):
|
||||||
|
found = True
|
||||||
|
for j in range(len(HAMLET)):
|
||||||
|
if line[i + j] != HAMLET[j] and line[i + j] != HAMLET[j].capitalize():
|
||||||
|
found = False
|
||||||
|
break
|
||||||
|
if found:
|
||||||
|
# print(ind + 1, ":", line[i:], end="")
|
||||||
|
hamlet_array_slow.append(ind + 1)
|
||||||
|
break
|
||||||
|
|
||||||
|
# print(*hamlet_array_slow, sep="\n")
|
||||||
|
|
||||||
|
print(time.time() - start_time)
|
||||||
|
|
||||||
|
# time this function
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
hamlet_array_fast = []
|
||||||
|
for ind, line in enumerate(text):
|
||||||
|
if HAMLET in line:
|
||||||
|
hamlet_array_fast.append(ind + 1)
|
||||||
|
print(time.time() - start_time)
|
41
TaskA02/run.py
Normal file
41
TaskA02/run.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
NUMBER_OF_INVOICES = 10
|
||||||
|
DIR = os.path.dirname(__file__)
|
||||||
|
PHRASE = "pies"
|
||||||
|
|
||||||
|
|
||||||
|
def join_path(filename: str) -> str:
|
||||||
|
return os.path.join(DIR, filename)
|
||||||
|
|
||||||
|
|
||||||
|
with open(join_path("simple.in"), "r", newline="", encoding="utf8") as file:
|
||||||
|
text = file.readlines()
|
||||||
|
|
||||||
|
|
||||||
|
def find_me():
|
||||||
|
for j in range(len(PHRASE)):
|
||||||
|
if line[i + j] != PHRASE[j] and line[i + j] != PHRASE[j].capitalize():
|
||||||
|
return False
|
||||||
|
|
||||||
|
if line[i - 1] not in [" ", "\t", "\n"]:
|
||||||
|
return False
|
||||||
|
if line[i + len(PHRASE)] not in [" ", "\t", "\n", "\r"]:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
found = True
|
||||||
|
phrase_array_slow = []
|
||||||
|
for ind, line in enumerate(text):
|
||||||
|
for i in range(len(line)):
|
||||||
|
found = True
|
||||||
|
found = find_me()
|
||||||
|
|
||||||
|
if found:
|
||||||
|
print(ind + 1, ":", line[i:], end="")
|
||||||
|
phrase_array_slow.append(ind + 1)
|
||||||
|
break
|
||||||
|
|
||||||
|
# print(*phrase_array_slow, sep="\n")
|
Loading…
Reference in New Issue
Block a user