Compare commits
3 Commits
87f198acc2
...
4d992a3879
Author | SHA1 | Date | |
---|---|---|---|
|
4d992a3879 | ||
|
5f91662b8e | ||
|
1060b283bf |
@ -1,5 +1,4 @@
|
||||
import os
|
||||
import time
|
||||
|
||||
|
||||
NUMBER_OF_INVOICES = 10
|
||||
@ -14,30 +13,18 @@ def join_path(filename: str) -> str:
|
||||
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():
|
||||
if line[i + j] != HAMLET[j]:
|
||||
found = False
|
||||
break
|
||||
if found:
|
||||
# print(ind + 1, ":", line[i:], end="")
|
||||
print(ind + 1, ":", line, 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)
|
||||
# print(len(phrase_array_slow))
|
||||
|
@ -44,8 +44,7 @@ for ind, line in enumerate(text):
|
||||
found = find_me()
|
||||
|
||||
if found:
|
||||
print(ind + 1, ":", line[i:], end="")
|
||||
print(ind + 1, ":", line, end="")
|
||||
phrase_array_slow.append(ind + 1)
|
||||
break
|
||||
|
||||
# print(*phrase_array_slow, sep="\n")
|
||||
# print(len(phrase_array_slow))
|
||||
|
File diff suppressed because one or more lines are too long
49
TaskA03/run.py
Normal file
49
TaskA03/run.py
Normal file
@ -0,0 +1,49 @@
|
||||
import os
|
||||
|
||||
|
||||
NUMBER_OF_INVOICES = 10
|
||||
DIR = os.path.dirname(__file__)
|
||||
PHRASE = "19** r."
|
||||
DIGITS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
with open(
|
||||
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
|
||||
) as file:
|
||||
text = file.readlines()
|
||||
|
||||
|
||||
def in_set(letter, set):
|
||||
for i in set:
|
||||
if i == letter:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def find_me():
|
||||
for j in range(len(PHRASE)):
|
||||
if PHRASE[j] == "*" and in_set(line[i + j], DIGITS):
|
||||
continue
|
||||
|
||||
if line[i + j] != PHRASE[j] and line[i + j] != PHRASE[j].capitalize():
|
||||
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, end="")
|
||||
phrase_array_slow.append(ind + 1)
|
||||
break
|
||||
# print(len(phrase_array_slow))
|
File diff suppressed because one or more lines are too long
44
TaskA04/run.py
Normal file
44
TaskA04/run.py
Normal file
@ -0,0 +1,44 @@
|
||||
import numbers
|
||||
import os
|
||||
|
||||
DIR = os.path.dirname(__file__)
|
||||
DIGITS = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
|
||||
|
||||
|
||||
def join_path(filename: str) -> str:
|
||||
return os.path.join(DIR, filename)
|
||||
|
||||
|
||||
def in_set(letter, set) -> bool:
|
||||
for i in set:
|
||||
if i == letter:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
with open(
|
||||
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
|
||||
) as file:
|
||||
text = file.readlines()
|
||||
|
||||
numbers = []
|
||||
for ind, line in enumerate(text):
|
||||
numbers_line = []
|
||||
i = 0
|
||||
while i < len(line):
|
||||
number = []
|
||||
if in_set(line[i], DIGITS):
|
||||
number.append(line[i])
|
||||
for j in range(i + 1, len(line)):
|
||||
if line[j].isdigit():
|
||||
number.append(line[j])
|
||||
else:
|
||||
i += len(number) - 1
|
||||
break
|
||||
numbers_line.append(int("".join(number)))
|
||||
i += 1
|
||||
|
||||
if len(numbers_line) != 0:
|
||||
print(*numbers_line, sep=" ")
|
||||
numbers.append(numbers_line)
|
||||
# print(len(phrase_array_slow))
|
Loading…
Reference in New Issue
Block a user