From 6900529ae370f11c8b93c6d1ccb7dfe1463ad083 Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 19:44:15 +0530 Subject: [PATCH 01/13] Addition_without_arithmetic --- maths/Addition_without_arithmetic.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 maths/Addition_without_arithmetic.py diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py new file mode 100644 index 000000000000..a089461bb5d3 --- /dev/null +++ b/maths/Addition_without_arithmetic.py @@ -0,0 +1,16 @@ +first=int(input("Enter the number for first: ")) +sec=int(input("Enter the number for sec: ")) +def add(first,sec): #Create a function + while(sec != 0): + + c=first&sec + + first=first^sec + + sec=c<<1 + return first + + + +print("Sum of two numbers",add(first,sec)) #call the function +# Display sum of two numbers From 93a617c2cf5885ee185cde56dff14a0ad03c7d67 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:20:47 +0000 Subject: [PATCH 02/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/Addition_without_arithmetic.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index a089461bb5d3..7c3008820b83 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -1,16 +1,17 @@ -first=int(input("Enter the number for first: ")) -sec=int(input("Enter the number for sec: ")) -def add(first,sec): #Create a function - while(sec != 0): +first = int(input("Enter the number for first: ")) +sec = int(input("Enter the number for sec: ")) - c=first&sec - first=first^sec +def add(first, sec): # Create a function + while sec != 0: - sec=c<<1 + c = first & sec + + first = first ^ sec + + sec = c << 1 return first - - -print("Sum of two numbers",add(first,sec)) #call the function + +print("Sum of two numbers", add(first, sec)) # call the function # Display sum of two numbers From c216f3ea404bf56eec5889132590c385c581b6b0 Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 20:15:05 +0530 Subject: [PATCH 03/13] added_param --- maths/Addition_without_arithmetic.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index 7c3008820b83..b8c6712b21fd 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -1,8 +1,26 @@ +""" +Illustrate how to add the integer without arithmetic operation +Author: suraj Kumar +Time Complexity: 1 +""" + + first = int(input("Enter the number for first: ")) sec = int(input("Enter the number for sec: ")) -def add(first, sec): # Create a function +def add(first, sec) -> int: # Create a function + """ + implementation of addition of integer + :param first: int + :param sec: int + :return: int + Examples: + >>> add(3,5) + 8 + >>> add(13,5) + 18 + """ while sec != 0: c = first & sec From d181b0b5b266fff5f0a46166c824457169b3105e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:48:44 +0000 Subject: [PATCH 04/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/Addition_without_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index b8c6712b21fd..a558f68c12a6 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -13,7 +13,7 @@ def add(first, sec) -> int: # Create a function """ implementation of addition of integer :param first: int - :param sec: int + :param sec: int :return: int Examples: >>> add(3,5) From f63609a4b074cd0f8a9b444832e69fa47d27327e Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 20:19:08 +0530 Subject: [PATCH 05/13] added_param_in_first_sec --- maths/Addition_without_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index b8c6712b21fd..f778b29fdb93 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -9,7 +9,7 @@ sec = int(input("Enter the number for sec: ")) -def add(first, sec) -> int: # Create a function +def add(first :int , sec : int) -> int: # Create a function """ implementation of addition of integer :param first: int From 80772320d003bf52304eb94ca2b9be9d12223665 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 14:50:28 +0000 Subject: [PATCH 06/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/Addition_without_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index 212d94aa9fea..06ac8e6b5aaa 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -9,7 +9,7 @@ sec = int(input("Enter the number for sec: ")) -def add(first :int , sec : int) -> int: # Create a function +def add(first: int, sec: int) -> int: # Create a function """ implementation of addition of integer :param first: int From 1b7f6089e77ab396e4ae0bb7d68ec210d1e1d12b Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 20:32:29 +0530 Subject: [PATCH 07/13] change_align --- maths/Addition_without_arithmetic.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index 06ac8e6b5aaa..4f2bc75efdb5 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -4,11 +4,6 @@ Time Complexity: 1 """ - -first = int(input("Enter the number for first: ")) -sec = int(input("Enter the number for sec: ")) - - def add(first: int, sec: int) -> int: # Create a function """ implementation of addition of integer @@ -30,6 +25,11 @@ def add(first: int, sec: int) -> int: # Create a function sec = c << 1 return first +if __name__ == "__main__": + import doctest -print("Sum of two numbers", add(first, sec)) # call the function -# Display sum of two numbers + doctest.testmod() + first = int(input("Enter the number for first: ")) + sec = int(input("Enter the number for sec: ")) + print("Sum of two numbers", add(first, sec)) + # Display sum of two numbers From 91d33817e0e36a8cc84833f30e8b33e0a18d4b33 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:04:03 +0000 Subject: [PATCH 08/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/Addition_without_arithmetic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index 4f2bc75efdb5..398b95a0dfd5 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -4,6 +4,7 @@ Time Complexity: 1 """ + def add(first: int, sec: int) -> int: # Create a function """ implementation of addition of integer @@ -25,6 +26,7 @@ def add(first: int, sec: int) -> int: # Create a function sec = c << 1 return first + if __name__ == "__main__": import doctest From e8da5dd9be695c9013bf14981fb5d1abce910c3a Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 21:03:30 +0530 Subject: [PATCH 09/13] Update Addition_without_arithmetic.py --- maths/Addition_without_arithmetic.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index 398b95a0dfd5..caaf4f3bb0c7 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -2,6 +2,7 @@ Illustrate how to add the integer without arithmetic operation Author: suraj Kumar Time Complexity: 1 +https://en.wikipedia.org/wiki/Bitwise_operation """ @@ -28,10 +29,11 @@ def add(first: int, sec: int) -> int: # Create a function if __name__ == "__main__": + first = int(input("Enter the number for first: ")) + sec = int(input("Enter the number for sec: ")) import doctest doctest.testmod() - first = int(input("Enter the number for first: ")) - sec = int(input("Enter the number for sec: ")) - print("Sum of two numbers", add(first, sec)) + + # print("Sum of two numbers", add(first, sec)) # Display sum of two numbers From 7b47d0e86deeb16c84faa653e66d7b0d9cc6137c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 8 Oct 2022 15:34:47 +0000 Subject: [PATCH 10/13] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/Addition_without_arithmetic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/Addition_without_arithmetic.py b/maths/Addition_without_arithmetic.py index caaf4f3bb0c7..24aa4eac601d 100644 --- a/maths/Addition_without_arithmetic.py +++ b/maths/Addition_without_arithmetic.py @@ -34,6 +34,6 @@ def add(first: int, sec: int) -> int: # Create a function import doctest doctest.testmod() - + # print("Sum of two numbers", add(first, sec)) # Display sum of two numbers From 66287869b6f414c97e3d1a6c76c814b6ed4536a1 Mon Sep 17 00:00:00 2001 From: kumarsurajsk <104374726+kumarsurajsk@users.noreply.github.com> Date: Sat, 8 Oct 2022 21:30:53 +0530 Subject: [PATCH 11/13] Rename Addition_without_arithmetic.py to addition_without_arithmetic.py --- ...ition_without_arithmetic.py => addition_without_arithmetic.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename maths/{Addition_without_arithmetic.py => addition_without_arithmetic.py} (100%) diff --git a/maths/Addition_without_arithmetic.py b/maths/addition_without_arithmetic.py similarity index 100% rename from maths/Addition_without_arithmetic.py rename to maths/addition_without_arithmetic.py From ec81b3f5c364fe0fc10c8efd647caaa8cae83fc7 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 12:59:24 +0100 Subject: [PATCH 12/13] Update addition_without_arithmetic.py --- maths/addition_without_arithmetic.py | 36 ++++++++++++++-------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/maths/addition_without_arithmetic.py b/maths/addition_without_arithmetic.py index 24aa4eac601d..9c145696a355 100644 --- a/maths/addition_without_arithmetic.py +++ b/maths/addition_without_arithmetic.py @@ -6,34 +6,34 @@ """ -def add(first: int, sec: int) -> int: # Create a function +def add(first: int, second: int) -> int: """ - implementation of addition of integer - :param first: int - :param sec: int - :return: int + Implementation of addition of integer + Examples: - >>> add(3,5) + >>> add(3, 5) 8 - >>> add(13,5) + >>> add(13, 5) 18 + >>> add(-7, 2) + -5 + >>> add(0, -7) + -7 + >>> add(-321, 0) + -321 """ - while sec != 0: - - c = first & sec - - first = first ^ sec - - sec = c << 1 + while second != 0: + c = first & second + first ^= second + second = c << 1 return first if __name__ == "__main__": - first = int(input("Enter the number for first: ")) - sec = int(input("Enter the number for sec: ")) import doctest doctest.testmod() - # print("Sum of two numbers", add(first, sec)) - # Display sum of two numbers + first = int(input("Enter the number for first: ")) + second = int(input("Enter the number for sec: ")) + print(f"{add(first, second) = }") From d9c821f28e4e17adfd86741ee088ad5c4dd2cf45 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Sun, 30 Oct 2022 13:00:45 +0100 Subject: [PATCH 13/13] Update addition_without_arithmetic.py --- maths/addition_without_arithmetic.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/maths/addition_without_arithmetic.py b/maths/addition_without_arithmetic.py index 9c145696a355..409604e4c08a 100644 --- a/maths/addition_without_arithmetic.py +++ b/maths/addition_without_arithmetic.py @@ -34,6 +34,6 @@ def add(first: int, second: int) -> int: doctest.testmod() - first = int(input("Enter the number for first: ")) - second = int(input("Enter the number for sec: ")) + first = int(input("Enter the first number: ").strip()) + second = int(input("Enter the second number: ").strip()) print(f"{add(first, second) = }")