From 926a9c3f88451dbaae7e7450e1cd11a8e4cbbf50 Mon Sep 17 00:00:00 2001 From: Nadya Shaporova Date: Thu, 23 Oct 2025 13:59:41 +0300 Subject: [PATCH 1/4] Add .gitignore file --- .gitignore | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9b7ba47 --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Created by https://www.toptal.com/developers/gitignore/api/venv +# Edit at https://www.toptal.com/developers/gitignore?templates=venv + +### venv ### +# Virtualenv +# http://iamzed.com/2009/05/07/a-primer-on-virtualenv/ +.Python +[Bb]in +[Ii]nclude +[Ll]ib +[Ll]ib64 +[Ll]ocal +[Ss]cripts +pyvenv.cfg +.venv +pip-selfcheck.json + +# End of https://www.toptal.com/developers/gitignore/api/venv From a7ea439748cba469f958381d2dfabdaf14dad77a Mon Sep 17 00:00:00 2001 From: Shaporova-Nadya Date: Thu, 23 Oct 2025 14:07:04 +0300 Subject: [PATCH 2/4] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dffe746 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 Shaporova-Nadya + +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. From b2e361005e327955f98d4422fecc30b379b6ef84 Mon Sep 17 00:00:00 2001 From: Nadya Shaporova Date: Thu, 23 Oct 2025 15:18:36 +0300 Subject: [PATCH 3/4] =?UTF-8?q?fast=5Fpow.py=20fixed=20=D0=A2=D0=B5=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D0=B0=20=D0=BE=D0=B1=D1=80=D0=B0=D0=B1=D0=B0=D1=82=D1=8B?= =?UTF-8?q?=D0=B2=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B5=D1=87=D0=B5=D1=82=D0=BD?= =?UTF-8?q?=D1=83=D1=8E=20=D1=81=D1=82=D0=B5=D0=BF=D0=B5=D0=BD=D1=8C=20?= =?UTF-8?q?=D0=B8=20=D1=81=D1=82=D0=B5=D0=BF=D0=B5=D0=BD=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=8C=D1=88=D0=B5=200?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fast_pow.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/fast_pow.py b/src/fast_pow.py index 1ba1dc1..b17fa05 100644 --- a/src/fast_pow.py +++ b/src/fast_pow.py @@ -1,6 +1,12 @@ def fastPow(number, power): - result = number - while power != 1: - result *= result - power = power // 2 + if power < 0: + return 1 + result = 1 + + while power > 0: + if power % 2 == 1: + result *= number + number *= number + power //= 2 + return result From a1b3d9f087c69288364580cfd289306d081e46cc Mon Sep 17 00:00:00 2001 From: Nadya Shaporova Date: Thu, 23 Oct 2025 15:22:25 +0300 Subject: [PATCH 4/4] Add unit tests --- test/test_fast_pow.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/test_fast_pow.py b/test/test_fast_pow.py index 5e4aebd..ac5b5ef 100644 --- a/test/test_fast_pow.py +++ b/test/test_fast_pow.py @@ -1,9 +1,11 @@ -from src.fast_pow import fastPow - +import pytest +from fast_pow import fastPow def test_two_power_two(): assert fastPow(2, 2) == 4 - def test_negative(): - assert fastPow(-1, 4) == 1 + assert fastPow(256, 0) == 1 + +def test_neg(): + assert fastPow(2, -4) == 1