This commit is contained in:
Uczelnia 2023-10-30 11:57:20 +01:00
commit 95f42e466e
7 changed files with 100288 additions and 23 deletions

176
.gitignore vendored Normal file
View File

@ -0,0 +1,176 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
# Local History for Visual Studio Code
.history/
# Built Visual Studio Code Extensions
*.vsix
#extionsion vsc counter
.VSCodeCounter

View File

@ -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))

View File

@ -10,18 +10,28 @@ def join_path(filename: str) -> str:
return os.path.join(DIR, filename)
with open(join_path("simple.in"), "r", newline="", encoding="utf8") as file:
with open(
join_path("polish_wiki_excerpt.in"), "r", newline="", encoding="utf8"
) as file:
text = file.readlines()
def not_in(letter, set):
for i in set:
if i == letter:
return False
return True
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"]:
if not_in(line[i - 1], [" ", "\n"]):
return False
if line[i + len(PHRASE)] not in [" ", "\t", "\n", "\r"]:
if not_in(line[i + len(PHRASE)], [" ", "\n", "\r"]):
return False
return True
@ -34,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
View 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
View 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))