From 7b6324e7dcd99adf9370e31c82101a0c3658a93d Mon Sep 17 00:00:00 2001 From: AasheeshLikePanner Date: Mon, 2 Oct 2023 22:22:55 +0530 Subject: [PATCH 1/2] Changing Name of file and adding doctests in file. --- DIRECTORY.md | 2 +- ...ntiation_2.py => binary_multiplication.py} | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) rename maths/{binary_exponentiation_2.py => binary_multiplication.py} (68%) diff --git a/DIRECTORY.md b/DIRECTORY.md index 7d3ceee144be..16ff73467c54 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -548,7 +548,7 @@ * [Basic Maths](maths/basic_maths.py) * [Binary Exp Mod](maths/binary_exp_mod.py) * [Binary Exponentiation](maths/binary_exponentiation.py) - * [Binary Exponentiation 2](maths/binary_exponentiation_2.py) + * [Binary Exponentiation 2](maths/binary_multiplication.py) * [Binary Exponentiation 3](maths/binary_exponentiation_3.py) * [Binomial Coefficient](maths/binomial_coefficient.py) * [Binomial Distribution](maths/binomial_distribution.py) diff --git a/maths/binary_exponentiation_2.py b/maths/binary_multiplication.py similarity index 68% rename from maths/binary_exponentiation_2.py rename to maths/binary_multiplication.py index af8f776dd266..55af8ec1d4a5 100644 --- a/maths/binary_exponentiation_2.py +++ b/maths/binary_multiplication.py @@ -12,6 +12,29 @@ def b_expo(a: int, b: int) -> int: + """ + Calculate the result of multiplying 'a' and 'b' using bitwise multiplication. + Parameters: + a (int): The first number. + b (int): The second number. + Returns: + int: The result of 'a' multiplied by 'b'. + Examples: + >>> b_expo(2, 3) + 6 + >>> b_expo(5, 0) + 0 + >>> b_expo(3, 4) + 12 + >>> b_expo(10, 5) + 50 + >>> b_expo(0, 5) + 0 + >>> b_expo(2, 1) + 2 + >>> b_expo(1, 10) + 10 + """ res = 0 while b > 0: if b & 1: @@ -22,6 +45,11 @@ def b_expo(a: int, b: int) -> int: return res +if __name__ == "__main__": + import doctest + + doctest.testmod() + def b_expo_mod(a: int, b: int, c: int) -> int: res = 0 From b2cc27cc2938d4eeba96404e2facb07830962fc4 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Oct 2023 16:54:49 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/binary_multiplication.py | 45 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/maths/binary_multiplication.py b/maths/binary_multiplication.py index 55af8ec1d4a5..dcac6e383fe0 100644 --- a/maths/binary_multiplication.py +++ b/maths/binary_multiplication.py @@ -13,28 +13,28 @@ def b_expo(a: int, b: int) -> int: """ - Calculate the result of multiplying 'a' and 'b' using bitwise multiplication. - Parameters: - a (int): The first number. - b (int): The second number. - Returns: - int: The result of 'a' multiplied by 'b'. - Examples: - >>> b_expo(2, 3) - 6 - >>> b_expo(5, 0) - 0 - >>> b_expo(3, 4) - 12 - >>> b_expo(10, 5) - 50 - >>> b_expo(0, 5) - 0 - >>> b_expo(2, 1) - 2 - >>> b_expo(1, 10) - 10 - """ + Calculate the result of multiplying 'a' and 'b' using bitwise multiplication. + Parameters: + a (int): The first number. + b (int): The second number. + Returns: + int: The result of 'a' multiplied by 'b'. + Examples: + >>> b_expo(2, 3) + 6 + >>> b_expo(5, 0) + 0 + >>> b_expo(3, 4) + 12 + >>> b_expo(10, 5) + 50 + >>> b_expo(0, 5) + 0 + >>> b_expo(2, 1) + 2 + >>> b_expo(1, 10) + 10 + """ res = 0 while b > 0: if b & 1: @@ -45,6 +45,7 @@ def b_expo(a: int, b: int) -> int: return res + if __name__ == "__main__": import doctest