Compare commits

..

No commits in common. "4d992a3879c1e6b12023768072356f7ba2b8ab7b" and "87f198acc206117f82a29c6c3da52178e78363e7" have entirely different histories.

6 changed files with 20 additions and 100099 deletions

View File

@ -1,4 +1,5 @@
import os
import time
NUMBER_OF_INVOICES = 10
@ -13,18 +14,30 @@ 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]:
if line[i + j] != HAMLET[j] and line[i + j] != HAMLET[j].capitalize():
found = False
break
if found:
print(ind + 1, ":", line, end="")
# print(ind + 1, ":", line[i:], end="")
hamlet_array_slow.append(ind + 1)
break
# print(len(phrase_array_slow))
# 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)

View File

@ -44,7 +44,8 @@ for ind, line in enumerate(text):
found = find_me()
if found:
print(ind + 1, ":", line, end="")
print(ind + 1, ":", line[i:], end="")
phrase_array_slow.append(ind + 1)
break
# print(len(phrase_array_slow))
# print(*phrase_array_slow, sep="\n")

File diff suppressed because one or more lines are too long

View File

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

View File

@ -1,44 +0,0 @@
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))