Merge branch 'master' of github.com:amirsoroush/PythonAlgorithms into bug-fix-expression-tree

This commit is contained in:
Amirsoroush 2023-04-25 16:02:02 +03:00
commit 01aebb0270
4 changed files with 16 additions and 9 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus - id: auto-walrus
- repo: https://github.com/charliermarsh/ruff-pre-commit - repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.0.261 rev: v0.0.262
hooks: hooks:
- id: ruff - id: ruff
@ -33,7 +33,7 @@ repos:
- tomli - tomli
- repo: https://github.com/tox-dev/pyproject-fmt - repo: https://github.com/tox-dev/pyproject-fmt
rev: "0.9.2" rev: "0.10.0"
hooks: hooks:
- id: pyproject-fmt - id: pyproject-fmt

View File

@ -327,6 +327,7 @@
* [Minimum Coin Change](dynamic_programming/minimum_coin_change.py) * [Minimum Coin Change](dynamic_programming/minimum_coin_change.py)
* [Minimum Cost Path](dynamic_programming/minimum_cost_path.py) * [Minimum Cost Path](dynamic_programming/minimum_cost_path.py)
* [Minimum Partition](dynamic_programming/minimum_partition.py) * [Minimum Partition](dynamic_programming/minimum_partition.py)
* [Minimum Size Subarray Sum](dynamic_programming/minimum_size_subarray_sum.py)
* [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py) * [Minimum Squares To Represent A Number](dynamic_programming/minimum_squares_to_represent_a_number.py)
* [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py) * [Minimum Steps To One](dynamic_programming/minimum_steps_to_one.py)
* [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py) * [Minimum Tickets Cost](dynamic_programming/minimum_tickets_cost.py)
@ -339,6 +340,7 @@
* [Word Break](dynamic_programming/word_break.py) * [Word Break](dynamic_programming/word_break.py)
## Electronics ## Electronics
* [Apparent Power](electronics/apparent_power.py)
* [Builtin Voltage](electronics/builtin_voltage.py) * [Builtin Voltage](electronics/builtin_voltage.py)
* [Carrier Concentration](electronics/carrier_concentration.py) * [Carrier Concentration](electronics/carrier_concentration.py)
* [Circular Convolution](electronics/circular_convolution.py) * [Circular Convolution](electronics/circular_convolution.py)
@ -348,6 +350,7 @@
* [Electrical Impedance](electronics/electrical_impedance.py) * [Electrical Impedance](electronics/electrical_impedance.py)
* [Ind Reactance](electronics/ind_reactance.py) * [Ind Reactance](electronics/ind_reactance.py)
* [Ohms Law](electronics/ohms_law.py) * [Ohms Law](electronics/ohms_law.py)
* [Real And Reactive Power](electronics/real_and_reactive_power.py)
* [Resistor Equivalence](electronics/resistor_equivalence.py) * [Resistor Equivalence](electronics/resistor_equivalence.py)
* [Resonant Frequency](electronics/resonant_frequency.py) * [Resonant Frequency](electronics/resonant_frequency.py)
@ -483,6 +486,7 @@
* [Astar](machine_learning/astar.py) * [Astar](machine_learning/astar.py)
* [Data Transformations](machine_learning/data_transformations.py) * [Data Transformations](machine_learning/data_transformations.py)
* [Decision Tree](machine_learning/decision_tree.py) * [Decision Tree](machine_learning/decision_tree.py)
* [Dimensionality Reduction](machine_learning/dimensionality_reduction.py)
* Forecasting * Forecasting
* [Run](machine_learning/forecasting/run.py) * [Run](machine_learning/forecasting/run.py)
* [Gradient Descent](machine_learning/gradient_descent.py) * [Gradient Descent](machine_learning/gradient_descent.py)
@ -604,6 +608,7 @@
* [Perfect Number](maths/perfect_number.py) * [Perfect Number](maths/perfect_number.py)
* [Perfect Square](maths/perfect_square.py) * [Perfect Square](maths/perfect_square.py)
* [Persistence](maths/persistence.py) * [Persistence](maths/persistence.py)
* [Pi Generator](maths/pi_generator.py)
* [Pi Monte Carlo Estimation](maths/pi_monte_carlo_estimation.py) * [Pi Monte Carlo Estimation](maths/pi_monte_carlo_estimation.py)
* [Points Are Collinear 3D](maths/points_are_collinear_3d.py) * [Points Are Collinear 3D](maths/points_are_collinear_3d.py)
* [Pollard Rho](maths/pollard_rho.py) * [Pollard Rho](maths/pollard_rho.py)

View File

@ -76,10 +76,11 @@ def encrypt_and_write_to_file(
key_size, n, e = read_key_file(key_filename) key_size, n, e = read_key_file(key_filename)
if key_size < block_size * 8: if key_size < block_size * 8:
sys.exit( sys.exit(
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher " "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher "
"requires the block size to be equal to or greater than the key size. " "requires the block size to be equal to or greater than the key size. "
"Either decrease the block size or use different keys." "Either decrease the block size or use different keys.".format(
% (block_size * 8, key_size) block_size * 8, key_size
)
) )
encrypted_blocks = [str(i) for i in encrypt_message(message, (n, e), block_size)] encrypted_blocks = [str(i) for i in encrypt_message(message, (n, e), block_size)]
@ -101,10 +102,11 @@ def read_from_file_and_decrypt(message_filename: str, key_filename: str) -> str:
if key_size < block_size * 8: if key_size < block_size * 8:
sys.exit( sys.exit(
"ERROR: Block size is %s bits and key size is %s bits. The RSA cipher " "ERROR: Block size is {} bits and key size is {} bits. The RSA cipher "
"requires the block size to be equal to or greater than the key size. " "requires the block size to be equal to or greater than the key size. "
"Did you specify the correct key file and encrypted file?" "Did you specify the correct key file and encrypted file?".format(
% (block_size * 8, key_size) block_size * 8, key_size
)
) )
encrypted_blocks = [] encrypted_blocks = []

View File

@ -399,7 +399,7 @@ def main():
if input("Press any key to restart or 'q' for quit: ").strip().lower() == "q": if input("Press any key to restart or 'q' for quit: ").strip().lower() == "q":
print("\n" + "GoodBye!".center(100, "-") + "\n") print("\n" + "GoodBye!".center(100, "-") + "\n")
break break
system("cls" if name == "nt" else "clear") system("clear" if name == "posix" else "cls") # noqa: S605
if __name__ == "__main__": if __name__ == "__main__":