Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 10 additions & 4 deletions src/fast_pow.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
def fastPow(number, power):

Check failure on line 1 in src/fast_pow.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (N802)

src/fast_pow.py:1:5: N802 Function name `fastPow` should be lowercase
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
10 changes: 6 additions & 4 deletions test/test_fast_pow.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from src.fast_pow import fastPow

import pytest

Check failure on line 1 in test/test_fast_pow.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (F401)

test/test_fast_pow.py:1:8: F401 `pytest` imported but unused
from fast_pow import fastPow

Check failure on line 2 in test/test_fast_pow.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (I001)

test/test_fast_pow.py:1:1: I001 Import block is un-sorted or un-formatted

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
Loading