Skip to content

New version with english comments #12762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 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
20 changes: 16 additions & 4 deletions boolean_algebra/and_gate.py
Original file line number Diff line number Diff line change
@@ -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 |
------------------------------
Expand All @@ -12,7 +12,7 @@
| 1 | 1 | 1 |
------------------------------

Refer - https://www.geeksforgeeks.org/logic-gates-in-python/
Refer - https://www.geeksforgeeks.org/logic-gates/
"""


Expand All @@ -32,6 +32,18 @@ def and_gate(input_1: int, input_2: int) -> int:
return int(input_1 and input_2)


def n_input_and_gate(inputs: list[int]) -> int:
"""
Calculate AND of a list of input values

>>> n_input_and_gate([1, 0, 1, 1, 0])
0
>>> n_input_and_gate([1, 1, 1, 1, 1])
1
"""
return int(all(inputs))


if __name__ == "__main__":
import doctest

Expand Down
40 changes: 40 additions & 0 deletions other/time_algo_exec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Author : Bosolindo Edhiengene Roger
# email : [email protected]

# This module contains codes about algorithms complexity as to estimate the time an algorithm

Check failure on line 4 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:4:89: E501 Line too long (93 > 88)
# will take to be run. Why do we find it usable ? Because, knowing this kind of information tells

Check failure on line 5 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:5:89: E501 Line too long (97 > 88)
# you if your code or solution is efficient or not ; it helps you not to fall trying to run such a code.

Check failure on line 6 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:6:89: E501 Line too long (104 > 88)


def calc(operations: dict) -> float:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/time_algo_exec.py, please provide doctest for the function calc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/time_algo_exec.py, please provide doctest for the function calc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/time_algo_exec.py, please provide doctest for the function calc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file other/time_algo_exec.py, please provide doctest for the function calc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What doctest for calc function are you talking about?

"""
calc(operation: dict) -> float:
This function aims to calculate how long an algorithm take, knowing only primary operations

Check failure on line 12 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:12:89: E501 Line too long (95 > 88)
:param operations: A dictionary where the values are tuples, consisting of the number of times

Check failure on line 13 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:13:89: E501 Line too long (98 > 88)
an operation is performed and its execution time, and the key should

Check failure on line 14 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:14:89: E501 Line too long (91 > 88)
preferably be the name of the operation for better clarity and usability.

Check failure on line 15 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:15:89: E501 Line too long (96 > 88)
:return: the time needed for the execution of this algorithm(if format is okey for "operations") or 0

Check failure on line 16 in other/time_algo_exec.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (E501)

other/time_algo_exec.py:16:89: E501 Line too long (105 > 88)
#>>> 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))
Loading