From b0be07bb04b2de4e2ee9b6cf61b465bdfceb7593 Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:45:32 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20power=20=D0=BD=D0=B0=200=20=D0=B8=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20power=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D1=86=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fast_pow.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 1ba1dc1..e7843f6 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -1,6 +1,11 @@ def fastPow(number, power): - result = number - while power != 1: - result *= result - power = power // 2 - return result + if power == 0: + return 1 + if power < 0: + return 1 / fastPow(number, -power) + else: + result = number + while power != 1: + result *= result + power = power // 2 + return result From 9f2303a797f74a7e06a8bccde0b375314dd550fa Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:46:18 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=D0=B9=20double=20=D0=BD=D0=B0=20=D1=81=D1=83=D0=BC=D0=BC?= =?UTF-8?q?=D1=83=20=D1=86=D0=B8=D1=84=D1=80=20double,=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=83=D1=82?= =?UTF-8?q?=D0=B8=D0=BB=D0=B8=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/luhn.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/luhn.py b/src/luhn.py index 11d993c..d2da690 100644 --- a/src/luhn.py +++ b/src/luhn.py @@ -1,14 +1,31 @@ def luhnСheck(cardNumber): digits = [int(d) for d in str(cardNumber) if d.isdigit()] control = digits.pop() - parity = (len(digits))%2 + parity = (len(digits)) % 2 total = 0 for i in range(len(digits)): if i % 2 == parity: doubled = digits[i] * 2 if doubled > 9: - doubled -= 9 + doubled = int(str(doubled)[0]) + int(str(doubled)[1]) + total += doubled total += doubled else: total += digits[i] return (total + control) % 10 == 0 + +flag = 1 +while flag: + test = input("Введите номер карты в формате XXXX XXXX XXXX XXXX или -1 для прекращения ввода: ") + if test == "-1": + flag = 0 + break + else: + if len(test) == 19 and len([i for i in test if i.isdigit()]) == 16: + if luhnСheck(test): + print("Correct") + else: + print("Incorrect") + + else: + print("Номер карты введен в неверном формате!") From 296120546d04a242dc21342113fed7641dc46a9b Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:47:06 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BE=D1=82=D1=80=D0=B8=D1=86=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B9=20=D0=B8=20=D0=BD=D1=83=D0=BB=D0=B5?= =?UTF-8?q?=D0=B2=D0=BE=D0=B9=20=D1=81=D1=82=D0=B5=D0=BF=D0=B5=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_fast_pow.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/test_fast_pow.py b/test/test_fast_pow.py index 5e4aebd..19af9a5 100644 --- a/test/test_fast_pow.py +++ b/test/test_fast_pow.py @@ -7,3 +7,9 @@ def test_two_power_two(): def test_negative(): assert fastPow(-1, 4) == 1 + +def test_negative_pow(): + assert fastPow(3, -2) == 1/9 + +def test_zero_pow(): + assert fastPow(100, 0) == 1 From f12fb960607d383caaa316b0efeb639fbdab782d Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:47:38 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BE?= =?UTF-8?q?=D0=BA=20=D1=86=D0=B8=D1=84=D1=80=20=D0=BD=D0=B0=20=D1=87=D0=B5?= =?UTF-8?q?=D1=82=D0=BD=D1=8B=D1=85=20=D0=BF=D0=BE=D0=B7=D0=B8=D1=86=D0=B8?= =?UTF-8?q?=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/test_luhn.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test_luhn.py b/test/test_luhn.py index 1c021a2..f961fc9 100644 --- a/test/test_luhn.py +++ b/test/test_luhn.py @@ -2,8 +2,14 @@ def test_good(): - assert luhnСheck("8571 2612 1234 5467") + assert luhnСheck("8571 2612 1234 5427") def test_bad(): - assert not luhnСheck("4561 2612 1234 5463") \ No newline at end of file + assert not luhnСheck("4561 2612 1234 5463") + +def test_good_even_positions_numbers(): + assert luhnСheck("9191 9191 9191 9194") + +def test_bad_even_positions_numbers(): + assert not luhnСheck("9191 9191 9191 9191") From 39451f6b2ba1be8fd8226a3a9f5a4c2fd3ea89a3 Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:48:27 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20.gitignore?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 209 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cc18fb2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,209 @@ +# Created by https://www.toptal.com/developers/gitignore/api/macos,python +# Edit at https://www.toptal.com/developers/gitignore?templates=macos,python + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Python ### +# 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/ + +### Python Patch ### +# Poetry local configuration file - https://python-poetry.org/docs/configuration/#local-configuration +poetry.toml + +# ruff +.ruff_cache/ + +# LSP config files +pyrightconfig.json + +# End of https://www.toptal.com/developers/gitignore/api/macos,python From 2956985836d8f0f5f8fa25196ab005127ef2cf7a Mon Sep 17 00:00:00 2001 From: Simonov Kirill <147266661+NewsPGG@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:49:36 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BB=D0=B8=D1=86=D0=B5=D0=BD=D0=B7=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4a63d13 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Simonov Kirill + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.