From a10b45de74f63e86852e64ceb2482b72d23233ad Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Thu, 5 Oct 2023 18:17:52 +0100 Subject: [PATCH 1/9] Add files via upload --- boolean_algebra/imply_gate.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 boolean_algebra/imply_gate.py diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py new file mode 100644 index 000000000000..65e539ed1f75 --- /dev/null +++ b/boolean_algebra/imply_gate.py @@ -0,0 +1,51 @@ +""" +An IMPLY Gate is a logic gate in boolean algebra which results to 1 if +either input 1 is 0, or if input 1 is 1, then imput 2 is 1. It is true is input 1 +implies input 2. + +Following is the truth table of an IMPLY Gate: + ------------------------------ + | Input 1 | Input 2 | Output | + ------------------------------ + | 0 | 0 | 1 | + | 0 | 1 | 1 | + | 1 | 0 | 0 | + | 1 | 1 | 1 | + ------------------------------ + +Refer - https://en.wikipedia.org/wiki/IMPLY_gate +""" + + +def imply_gate(input_1: int, input_2: int) -> int: + """ + Calculate IMPLY of the input values + + >>> imply_gate(0, 0) + 1 + >>> imply_gate(0, 1) + 1 + >>> imply_gate(1, 0) + 0 + >>> imply_gate(1, 1) + 1 + """ + return int((input_1 == 0) or (input_2 == 1)) + + +def test_imply_gate() -> None: + """ + Tests the and_gate function + """ + assert imply_gate(0, 0) == 1 + assert imply_gate(0, 1) == 1 + assert imply_gate(1, 0) == 0 + assert imply_gate(1, 1) == 1 + + +if __name__ == "__main__": + test_imply_gate() + print(imply_gate(0, 0)) + print(imply_gate(0, 1)) + print(imply_gate(1, 0)) + print(imply_gate(1, 1)) \ No newline at end of file From 5a3800ad0d8733aae0ebad5fc8cba36ac2f4c9d7 Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:18:57 +0000 Subject: [PATCH 2/9] Update imply_gate.py --- boolean_algebra/imply_gate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 65e539ed1f75..8a7b96db190e 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -1,7 +1,7 @@ """ An IMPLY Gate is a logic gate in boolean algebra which results to 1 if -either input 1 is 0, or if input 1 is 1, then imput 2 is 1. It is true is input 1 -implies input 2. +either input 1 is 0, or if input 1 is 1, then the output is 1 only if input 2 is 1. +It is true if input 1 implies input 2. Following is the truth table of an IMPLY Gate: ------------------------------ @@ -48,4 +48,4 @@ def test_imply_gate() -> None: print(imply_gate(0, 0)) print(imply_gate(0, 1)) print(imply_gate(1, 0)) - print(imply_gate(1, 1)) \ No newline at end of file + print(imply_gate(1, 1)) From ebf0f1c0dc4cb46e10547f7ed3941ebd3998a37a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:22:30 +0000 Subject: [PATCH 3/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- boolean_algebra/imply_gate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 8a7b96db190e..344b35d6ca65 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -1,6 +1,6 @@ """ -An IMPLY Gate is a logic gate in boolean algebra which results to 1 if -either input 1 is 0, or if input 1 is 1, then the output is 1 only if input 2 is 1. +An IMPLY Gate is a logic gate in boolean algebra which results to 1 if +either input 1 is 0, or if input 1 is 1, then the output is 1 only if input 2 is 1. It is true if input 1 implies input 2. Following is the truth table of an IMPLY Gate: From c2f6fb763e0ad16bab86773bd3fde05f3714d121 Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Sun, 8 Oct 2023 18:26:44 +0000 Subject: [PATCH 4/9] Update boolean_algebra/imply_gate.py Co-authored-by: Tianyi Zheng --- boolean_algebra/imply_gate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 344b35d6ca65..67f7085dcc11 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -30,7 +30,7 @@ def imply_gate(input_1: int, input_2: int) -> int: >>> imply_gate(1, 1) 1 """ - return int((input_1 == 0) or (input_2 == 1)) + return int(input_1 == 0 or input_2 == 1) def test_imply_gate() -> None: From 07669a61a1f8a55df0d611e4d7d1dc602af8f177 Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:22:57 +0000 Subject: [PATCH 5/9] Update imply_gate.py Made changes requested --- boolean_algebra/imply_gate.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 67f7085dcc11..25a01c92dd33 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -32,17 +32,6 @@ def imply_gate(input_1: int, input_2: int) -> int: """ return int(input_1 == 0 or input_2 == 1) - -def test_imply_gate() -> None: - """ - Tests the and_gate function - """ - assert imply_gate(0, 0) == 1 - assert imply_gate(0, 1) == 1 - assert imply_gate(1, 0) == 0 - assert imply_gate(1, 1) == 1 - - if __name__ == "__main__": test_imply_gate() print(imply_gate(0, 0)) From 81dd9315983d4b36e09aded7884ed52e461c0a7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:23:27 +0000 Subject: [PATCH 6/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- boolean_algebra/imply_gate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 25a01c92dd33..04183207be2f 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -32,6 +32,7 @@ def imply_gate(input_1: int, input_2: int) -> int: """ return int(input_1 == 0 or input_2 == 1) + if __name__ == "__main__": test_imply_gate() print(imply_gate(0, 0)) From 553a74dd1a6b603ca26f37b4bb8c7d34393f19cf Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Thu, 12 Oct 2023 09:28:42 +0000 Subject: [PATCH 7/9] Update imply_gate.py --- boolean_algebra/imply_gate.py | 1 - 1 file changed, 1 deletion(-) diff --git a/boolean_algebra/imply_gate.py b/boolean_algebra/imply_gate.py index 04183207be2f..151a7ad6439a 100644 --- a/boolean_algebra/imply_gate.py +++ b/boolean_algebra/imply_gate.py @@ -34,7 +34,6 @@ def imply_gate(input_1: int, input_2: int) -> int: if __name__ == "__main__": - test_imply_gate() print(imply_gate(0, 0)) print(imply_gate(0, 1)) print(imply_gate(1, 0)) From f50c3e6ac83b322c5e4e8b67f20ef9c91a0f9557 Mon Sep 17 00:00:00 2001 From: Daniela Large <133594563+dannylarge144@users.noreply.github.com> Date: Fri, 13 Oct 2023 00:39:20 +0100 Subject: [PATCH 8/9] Added nimply gate --- boolean_algebra/nimply_gate.py | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 boolean_algebra/nimply_gate.py diff --git a/boolean_algebra/nimply_gate.py b/boolean_algebra/nimply_gate.py new file mode 100644 index 000000000000..e54714dece51 --- /dev/null +++ b/boolean_algebra/nimply_gate.py @@ -0,0 +1,40 @@ +""" +An NIMPLY Gate is a logic gate in boolean algebra which results to 0 if +either input 1 is 0, or if input 1 is 1, then it is 0 only if input 2 is 1. +It is false if input 1 implies input 2. It is the negated form of imply + +Following is the truth table of an NIMPLY Gate: + ------------------------------ + | Input 1 | Input 2 | Output | + ------------------------------ + | 0 | 0 | 0 | + | 0 | 1 | 0 | + | 1 | 0 | 1 | + | 1 | 1 | 0 | + ------------------------------ + +Refer - https://en.wikipedia.org/wiki/NIMPLY_gate +""" + + +def nimply_gate(input_1: int, input_2: int) -> int: + """ + Calculate NIMPLY of the input values + + >>> nimply_gate(0, 0) + 0 + >>> nimply_gate(0, 1) + 0 + >>> nimply_gate(1, 0) + 1 + >>> nimply_gate(1, 1) + 0 + """ + return int(input_1 == 1 and input_2 == 0) + + +if __name__ == "__main__": + print(nimply_gate(0, 0)) + print(nimply_gate(0, 1)) + print(nimply_gate(1, 0)) + print(nimply_gate(1, 1)) \ No newline at end of file From 734f9a5307c300f6598c2f66bab21ec6471adbe9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 12 Oct 2023 23:42:08 +0000 Subject: [PATCH 9/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- boolean_algebra/nimply_gate.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boolean_algebra/nimply_gate.py b/boolean_algebra/nimply_gate.py index e54714dece51..6e34332d9112 100644 --- a/boolean_algebra/nimply_gate.py +++ b/boolean_algebra/nimply_gate.py @@ -1,6 +1,6 @@ """ -An NIMPLY Gate is a logic gate in boolean algebra which results to 0 if -either input 1 is 0, or if input 1 is 1, then it is 0 only if input 2 is 1. +An NIMPLY Gate is a logic gate in boolean algebra which results to 0 if +either input 1 is 0, or if input 1 is 1, then it is 0 only if input 2 is 1. It is false if input 1 implies input 2. It is the negated form of imply Following is the truth table of an NIMPLY Gate: @@ -37,4 +37,4 @@ def nimply_gate(input_1: int, input_2: int) -> int: print(nimply_gate(0, 0)) print(nimply_gate(0, 1)) print(nimply_gate(1, 0)) - print(nimply_gate(1, 1)) \ No newline at end of file + print(nimply_gate(1, 1))