From 927fc55ba9d6bca9cc4981f157ccd33bbbad9029 Mon Sep 17 00:00:00 2001 From: robohie Date: Fri, 9 May 2025 15:57:07 +0100 Subject: [PATCH 01/15] Update and_gate.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit J'ai nourri ce programme en ajoutant une porte And à n entrées. --- boolean_algebra/and_gate.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/boolean_algebra/and_gate.py b/boolean_algebra/and_gate.py index 6ae66b5b0a77..3991d0042c95 100644 --- a/boolean_algebra/and_gate.py +++ b/boolean_algebra/and_gate.py @@ -32,6 +32,18 @@ def and_gate(input_1: int, input_2: int) -> int: return int(input_1 and input_2) +def n_and_gate(inputs: tuple) -> int: + """ + Calcul le And de la liste des nombres + binaires fournie. Nécessaire pour + implémenter une porte And à n entrées + Par exemple + >>> n_and_gate((1, 0, 1, 1, 0)) + 0 + """ + return int(all(inputs)) + + if __name__ == "__main__": import doctest From c54f7bbc9a51f7e0b25b3f0527319da3c3aceed6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 15:07:11 +0000 Subject: [PATCH 02/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- boolean_algebra/and_gate.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/boolean_algebra/and_gate.py b/boolean_algebra/and_gate.py index 3991d0042c95..9c09b7b2e219 100644 --- a/boolean_algebra/and_gate.py +++ b/boolean_algebra/and_gate.py @@ -33,15 +33,15 @@ def and_gate(input_1: int, input_2: int) -> int: def n_and_gate(inputs: tuple) -> int: - """ - Calcul le And de la liste des nombres - binaires fournie. Nécessaire pour - implémenter une porte And à n entrées - Par exemple - >>> n_and_gate((1, 0, 1, 1, 0)) - 0 - """ - return int(all(inputs)) + """ + Calcul le And de la liste des nombres + binaires fournie. Nécessaire pour + implémenter une porte And à n entrées + Par exemple + >>> n_and_gate((1, 0, 1, 1, 0)) + 0 + """ + return int(all(inputs)) if __name__ == "__main__": From 7072b86b42493909590a88989fa3cb8ca773bc8f Mon Sep 17 00:00:00 2001 From: robohie Date: Fri, 9 May 2025 16:13:00 +0100 Subject: [PATCH 03/15] Update and_gate.py Commentaires en anglais --- boolean_algebra/and_gate.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/boolean_algebra/and_gate.py b/boolean_algebra/and_gate.py index 9c09b7b2e219..58175fb0541b 100644 --- a/boolean_algebra/and_gate.py +++ b/boolean_algebra/and_gate.py @@ -34,10 +34,8 @@ def and_gate(input_1: int, input_2: int) -> int: def n_and_gate(inputs: tuple) -> int: """ - Calcul le And de la liste des nombres - binaires fournie. Nécessaire pour - implémenter une porte And à n entrées - Par exemple + Calculate AND of a list of input values + >>> n_and_gate((1, 0, 1, 1, 0)) 0 """ From 9b2962620e61937ed6fc8ab5e92395969422871f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 9 May 2025 15:17:58 +0000 Subject: [PATCH 04/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- boolean_algebra/and_gate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boolean_algebra/and_gate.py b/boolean_algebra/and_gate.py index 58175fb0541b..15133be9cc0b 100644 --- a/boolean_algebra/and_gate.py +++ b/boolean_algebra/and_gate.py @@ -35,7 +35,7 @@ def and_gate(input_1: int, input_2: int) -> int: def n_and_gate(inputs: tuple) -> int: """ Calculate AND of a list of input values - + >>> n_and_gate((1, 0, 1, 1, 0)) 0 """ From 6806a7a0cd60e9d6671c1549c153fca241889af2 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sat, 10 May 2025 14:44:03 +0300 Subject: [PATCH 05/15] Update and_gate.py --- boolean_algebra/and_gate.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/boolean_algebra/and_gate.py b/boolean_algebra/and_gate.py index 15133be9cc0b..650017b7ae10 100644 --- a/boolean_algebra/and_gate.py +++ b/boolean_algebra/and_gate.py @@ -1,8 +1,8 @@ """ -An AND Gate is a logic gate in boolean algebra which results to 1 (True) if both the -inputs are 1, and 0 (False) otherwise. +An AND Gate is a logic gate in boolean algebra which results to 1 (True) if all the +inputs are 1 (True), and 0 (False) otherwise. -Following is the truth table of an AND Gate: +Following is the truth table of a Two Input AND Gate: ------------------------------ | Input 1 | Input 2 | Output | ------------------------------ @@ -12,7 +12,7 @@ | 1 | 1 | 1 | ------------------------------ -Refer - https://www.geeksforgeeks.org/logic-gates-in-python/ +Refer - https://www.geeksforgeeks.org/logic-gates/ """ @@ -32,12 +32,14 @@ def and_gate(input_1: int, input_2: int) -> int: return int(input_1 and input_2) -def n_and_gate(inputs: tuple) -> int: +def n_input_and_gate(inputs: list[int]) -> int: """ Calculate AND of a list of input values - >>> n_and_gate((1, 0, 1, 1, 0)) + >>> n_input_and_gate([1, 0, 1, 1, 0]) 0 + >>> n_input_and_gate([1, 1, 1, 1, 1]) + 1 """ return int(all(inputs)) From 48f8920cef79ef5d3f93eb224a027c989e074c17 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 14:35:13 +0100 Subject: [PATCH 06/15] Module to calulate algorithms' time execution This add is about algorithms' complexity. The goal is to be able, for a given algorithm, knowing primary operations and their execution time, to predict how long it will take --- other/time_algo_exec.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 other/time_algo_exec.py diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py new file mode 100644 index 000000000000..0983508b8d2f --- /dev/null +++ b/other/time_algo_exec.py @@ -0,0 +1,37 @@ +# Auteur : Bosolindo Edhiengene Roger +# email : rogerbosolinndo34@gmail.com + +def calc(operations: dict) -> float: + """ + calc(operation: dict) -> float: + Ce programme sert à calculer le temps d'éxecution des algorithmes en fonction + des opérations primitives traitées + :param operations: dictionnaire des couples (nombre de fois, temps d'exécution) + avec comme clé, l'opération primitive(de préférence) + :return: le temps d'exécution de l'algorithme si le format de "operations" est bon, + 0 sinon + + #>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} + #>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} + #>>> calc(operations1) + #>>> 0.4 + #>>> calc(operations2) + #>>> 0 + """ + temps = 0 + for couple in operations.values(): + if len(couple) != 2: + return 0 + temps += couple[0] * couple[1] + + return temps + + +if __name__ == "__main__": + import doctest + + doctest.testmod() + operations1 = {"addition": (2, 0.1), "subtraction": (1, 0.2)} + operations2 = {"addition": (2, 0.1), "subtraction": (1, 0.2, 1)} + print(calc(operations1)) + print(calc(operations2)) From daac334bf2a7dd2e6a4c1be18ed014f8a5b35abe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 21 May 2025 13:39:56 +0000 Subject: [PATCH 07/15] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- other/time_algo_exec.py | 1 + 1 file changed, 1 insertion(+) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index 0983508b8d2f..df4626bf15ed 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -1,6 +1,7 @@ # Auteur : Bosolindo Edhiengene Roger # email : rogerbosolinndo34@gmail.com + def calc(operations: dict) -> float: """ calc(operation: dict) -> float: From b0ada1106d5fa85cd6b9e49e8728f3871b9545b6 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 14:57:57 +0100 Subject: [PATCH 08/15] Update time_algo_exec.py --- other/time_algo_exec.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index df4626bf15ed..7b808c6cbc51 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -5,13 +5,11 @@ def calc(operations: dict) -> float: """ calc(operation: dict) -> float: - Ce programme sert à calculer le temps d'éxecution des algorithmes en fonction - des opérations primitives traitées - :param operations: dictionnaire des couples (nombre de fois, temps d'exécution) - avec comme clé, l'opération primitive(de préférence) - :return: le temps d'exécution de l'algorithme si le format de "operations" est bon, - 0 sinon - + This function aims to calculate how long an algorithm take, knowing only primary operations + :param operations: A dictionary where the values are tuples, consisting of the number of times + an operation is performed and its execution time, and the key should + preferably be the name of the operation for better clarity and usability. + :return: the time needed for the execution of this algorithm(if format is okey for "operations") or 0 #>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} #>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} #>>> calc(operations1) From c58ef371af115b05f9ba113dbee8140f601239f7 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:09:20 +0100 Subject: [PATCH 09/15] Update time_algo_exec.py --- other/time_algo_exec.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index 7b808c6cbc51..af2b4cedfb16 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -1,5 +1,9 @@ -# Auteur : Bosolindo Edhiengene Roger -# email : rogerbosolinndo34@gmail.com +# Author : Bosolindo Edhiengene Roger +# email : rogerbosolinndo34@gmail.com + +# This module contains codes about algorithms complexity as to estimate the time an algorithm +# will take to be run. Why do we find it usable ? Because, knowing this kind of information tells +# you if your code or solution is efficient or not ; it helps you not to fall trying to run such a code. def calc(operations: dict) -> float: From b374385ad9a54ac8daf56674566e58df65b42d97 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:17:26 +0100 Subject: [PATCH 10/15] Update time_algo_exec.py --- other/time_algo_exec.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index af2b4cedfb16..ec7aa419fdae 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -2,8 +2,9 @@ # email : rogerbosolinndo34@gmail.com # This module contains codes about algorithms complexity as to estimate the time an algorithm -# will take to be run. Why do we find it usable ? Because, knowing this kind of information tells -# you if your code or solution is efficient or not ; it helps you not to fall trying to run such a code. +# will take to be run. +# Why do we find it usable ? Because, knowing this kind of information tells you if your code +# or solution is efficient or not ; it helps you not to fall trying to run such a code. def calc(operations: dict) -> float: From 083c94576a20ecb7643dc13ff0206cd130809f2c Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:18:30 +0100 Subject: [PATCH 11/15] Update time_algo_exec.py --- other/time_algo_exec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index ec7aa419fdae..1d4256b069ff 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -1,8 +1,8 @@ # Author : Bosolindo Edhiengene Roger # email : rogerbosolinndo34@gmail.com -# This module contains codes about algorithms complexity as to estimate the time an algorithm -# will take to be run. +# This module contains codes about algorithms complexity as to estimate the time +# an algorithm will take to be run. # Why do we find it usable ? Because, knowing this kind of information tells you if your code # or solution is efficient or not ; it helps you not to fall trying to run such a code. From f8f7ed1d65acbce3cc6db7e9803b4fbd49333a47 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:26:59 +0100 Subject: [PATCH 12/15] Update time_algo_exec.py --- other/time_algo_exec.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index 1d4256b069ff..62e88ae596b9 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -3,18 +3,21 @@ # This module contains codes about algorithms complexity as to estimate the time # an algorithm will take to be run. -# Why do we find it usable ? Because, knowing this kind of information tells you if your code -# or solution is efficient or not ; it helps you not to fall trying to run such a code. +# Why do we find it usable ? +# Because, knowing this kind of information tells you if your code or solution is +# efficient or not ; it helps you not to fall trying to run such a code. def calc(operations: dict) -> float: """ calc(operation: dict) -> float: - This function aims to calculate how long an algorithm take, knowing only primary operations - :param operations: A dictionary where the values are tuples, consisting of the number of times - an operation is performed and its execution time, and the key should - preferably be the name of the operation for better clarity and usability. - :return: the time needed for the execution of this algorithm(if format is okey for "operations") or 0 + This function aims to calculate how long an algorithm take, + knowing only primary operations + :param operations: + A dictionary where the values are tuples, consisting of the number of times + an operation is performed and its execution time, and the key should, + preferably, be the name of the operation for better clarity and usability. + :return: the time needed for the execution of this algorithm #>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} #>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} #>>> calc(operations1) @@ -24,8 +27,10 @@ def calc(operations: dict) -> float: """ temps = 0 for couple in operations.values(): + # Case you give a shorter or a longer tuple if len(couple) != 2: return 0 + # Otherwise temps += couple[0] * couple[1] return temps From 27cf6219465cc14d54a540dc8e75b8200bfafed4 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:45:01 +0100 Subject: [PATCH 13/15] Update time_algo_exec.py Fixing doctest problem --- other/time_algo_exec.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index 62e88ae596b9..2a41662b5387 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -18,12 +18,12 @@ def calc(operations: dict) -> float: an operation is performed and its execution time, and the key should, preferably, be the name of the operation for better clarity and usability. :return: the time needed for the execution of this algorithm - #>>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} - #>>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} - #>>> calc(operations1) - #>>> 0.4 - #>>> calc(operations2) - #>>> 0 + >>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} + >>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} + >>> calc(operations1) + >>> 0.4 + >>> calc(operations2) + >>> 0 """ temps = 0 for couple in operations.values(): @@ -40,7 +40,3 @@ def calc(operations: dict) -> float: import doctest doctest.testmod() - operations1 = {"addition": (2, 0.1), "subtraction": (1, 0.2)} - operations2 = {"addition": (2, 0.1), "subtraction": (1, 0.2, 1)} - print(calc(operations1)) - print(calc(operations2)) From 3a3671c8e83fa04b19e7b15a2d796fc821a1a8f9 Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 15:51:28 +0100 Subject: [PATCH 14/15] Update time_algo_exec.py From 76e1190e507e5e28fee7346ff15f55bd5d66e02e Mon Sep 17 00:00:00 2001 From: robohie Date: Wed, 21 May 2025 16:00:30 +0100 Subject: [PATCH 15/15] Update time_algo_exec.py --- other/time_algo_exec.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/time_algo_exec.py b/other/time_algo_exec.py index 2a41662b5387..39b251ef8e64 100644 --- a/other/time_algo_exec.py +++ b/other/time_algo_exec.py @@ -21,9 +21,9 @@ def calc(operations: dict) -> float: >>> operations1 = {"addition":(2, 0.1), "subtraction":(1, 0.2)} >>> operations2 = {"addition":(2, 0.1), "subtraction":(1, 0.2, 1)} >>> calc(operations1) - >>> 0.4 + 0.4 >>> calc(operations2) - >>> 0 + 0 """ temps = 0 for couple in operations.values():