From 4ef7d138cc1d2ec65474d7e2ddae614192d289d7 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:41:01 +0000 Subject: [PATCH 1/8] updating DIRECTORY.md --- DIRECTORY.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 16e6b7ae3e3e..d6ecb0d6533f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -55,6 +55,7 @@ * [Modular Division](blockchain/modular_division.py) ## Boolean Algebra + * [And Gate](boolean_algebra/and_gate.py) * [Norgate](boolean_algebra/norgate.py) * [Quine Mc Cluskey](boolean_algebra/quine_mc_cluskey.py) @@ -948,6 +949,7 @@ * [Quantum Random](quantum/quantum_random.py) * [Ripple Adder Classic](quantum/ripple_adder_classic.py) * [Single Qubit Measure](quantum/single_qubit_measure.py) + * [Superdense Coding](quantum/superdense_coding.py) ## Scheduling * [First Come First Served](scheduling/first_come_first_served.py) @@ -1037,7 +1039,6 @@ * [Can String Be Rearranged As Palindrome](strings/can_string_be_rearranged_as_palindrome.py) * [Capitalize](strings/capitalize.py) * [Check Anagrams](strings/check_anagrams.py) - * [Check Pangram](strings/check_pangram.py) * [Credit Card Validator](strings/credit_card_validator.py) * [Detecting English Programmatically](strings/detecting_english_programmatically.py) * [Dna](strings/dna.py) @@ -1046,6 +1047,8 @@ * [Indian Phone Validator](strings/indian_phone_validator.py) * [Is Contains Unique Chars](strings/is_contains_unique_chars.py) * [Is Palindrome](strings/is_palindrome.py) + * [Is Pangram](strings/is_pangram.py) + * [Is Spain National Id](strings/is_spain_national_id.py) * [Jaro Winkler](strings/jaro_winkler.py) * [Join](strings/join.py) * [Knuth Morris Pratt](strings/knuth_morris_pratt.py) @@ -1090,6 +1093,7 @@ * [Fetch Well Rx Price](web_programming/fetch_well_rx_price.py) * [Get Imdb Top 250 Movies Csv](web_programming/get_imdb_top_250_movies_csv.py) * [Get Imdbtop](web_programming/get_imdbtop.py) + * [Get Top Billioners](web_programming/get_top_billioners.py) * [Get Top Hn Posts](web_programming/get_top_hn_posts.py) * [Get User Tweets](web_programming/get_user_tweets.py) * [Giphy](web_programming/giphy.py) From 1ed8713fcd1710d8aae85c81ac4dd57af19eeb87 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:20:32 +0000 Subject: [PATCH 2/8] updating DIRECTORY.md --- DIRECTORY.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 5c4a032db6cd..f6889f09a03a 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -48,6 +48,7 @@ * [Highest Set Bit](bit_manipulation/highest_set_bit.py) * [Index Of Rightmost Set Bit](bit_manipulation/index_of_rightmost_set_bit.py) * [Is Even](bit_manipulation/is_even.py) + * [Is Power Of Two](bit_manipulation/is_power_of_two.py) * [Reverse Bits](bit_manipulation/reverse_bits.py) * [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py) @@ -315,6 +316,7 @@ * [Minimum Partition](dynamic_programming/minimum_partition.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 Tickets Cost](dynamic_programming/minimum_tickets_cost.py) * [Optimal Binary Search Tree](dynamic_programming/optimal_binary_search_tree.py) * [Palindrome Partitioning](dynamic_programming/palindrome_partitioning.py) * [Rod Cutting](dynamic_programming/rod_cutting.py) @@ -496,8 +498,6 @@ ## Maths * [3N Plus 1](maths/3n_plus_1.py) * [Abs](maths/abs.py) - * [Abs Max](maths/abs_max.py) - * [Abs Min](maths/abs_min.py) * [Add](maths/add.py) * [Addition Without Arithmetic](maths/addition_without_arithmetic.py) * [Aliquot Sum](maths/aliquot_sum.py) @@ -653,6 +653,7 @@ * [Matrix Operation](matrix/matrix_operation.py) * [Max Area Of Island](matrix/max_area_of_island.py) * [Nth Fibonacci Using Matrix Exponentiation](matrix/nth_fibonacci_using_matrix_exponentiation.py) + * [Pascal Triangle](matrix/pascal_triangle.py) * [Rotate Matrix](matrix/rotate_matrix.py) * [Searching In Sorted Matrix](matrix/searching_in_sorted_matrix.py) * [Sherman Morrison](matrix/sherman_morrison.py) @@ -689,7 +690,6 @@ * [Magicdiamondpattern](other/magicdiamondpattern.py) * [Maximum Subarray](other/maximum_subarray.py) * [Nested Brackets](other/nested_brackets.py) - * [Pascal Triangle](other/pascal_triangle.py) * [Password Generator](other/password_generator.py) * [Quine](other/quine.py) * [Scoring Algorithm](other/scoring_algorithm.py) @@ -701,6 +701,7 @@ * [Casimir Effect](physics/casimir_effect.py) * [Centripetal Force](physics/centripetal_force.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) + * [Hubble Parameter](physics/hubble_parameter.py) * [Ideal Gas Law](physics/ideal_gas_law.py) * [Kinetic Energy](physics/kinetic_energy.py) * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) From c668796f3c27c0c25e5982f4ac5f745757ebeb0f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Wed, 2 Nov 2022 16:21:47 +0000 Subject: [PATCH 3/8] updating DIRECTORY.md --- DIRECTORY.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index f6889f09a03a..a2112bcfb7b4 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -675,7 +675,6 @@ ## Other * [Activity Selection](other/activity_selection.py) * [Alternative List Arrange](other/alternative_list_arrange.py) - * [Check Strong Password](other/check_strong_password.py) * [Davisb Putnamb Logemannb Loveland](other/davisb_putnamb_logemannb_loveland.py) * [Dijkstra Bankers Algorithm](other/dijkstra_bankers_algorithm.py) * [Doomsday](other/doomsday.py) @@ -690,7 +689,7 @@ * [Magicdiamondpattern](other/magicdiamondpattern.py) * [Maximum Subarray](other/maximum_subarray.py) * [Nested Brackets](other/nested_brackets.py) - * [Password Generator](other/password_generator.py) + * [Password](other/password.py) * [Quine](other/quine.py) * [Scoring Algorithm](other/scoring_algorithm.py) * [Sdes](other/sdes.py) From 9933878578626c91a04c479c958ca01e8f8223ed Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Wed, 2 Nov 2022 19:48:20 +0300 Subject: [PATCH 4/8] Lower the --max-complexity threshold in the file .flake8 --- .flake8 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 0d9ef18d142b..b20c76329b54 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,6 @@ [flake8] max-line-length = 88 -max-complexity = 25 +max-complexity = 21 extend-ignore = A003 # Class attribute is shadowing a python builtin # Formatting style for `black` From 38ac4c059540d910370b6525f9c2eae3020c6a63 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Wed, 2 Nov 2022 20:53:07 +0300 Subject: [PATCH 5/8] Reduce the complexity of linear_algebra/src/polynom_for_points.py --- linear_algebra/src/polynom_for_points.py | 139 ++++++++++------------- 1 file changed, 61 insertions(+), 78 deletions(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index 091849542ffe..84b4bc770835 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -24,96 +24,79 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: >>> print(points_to_polynomial([[1, 5], [2, 2], [3, 9]])) f(x)=x^2*5.0+x^1*-18.0+x^0*18.0 """ - try: - check = 1 - more_check = 0 - d = coordinates[0][0] - for j in range(len(coordinates)): - if j == 0: - continue - if d == coordinates[j][0]: - more_check += 1 - solved = "x=" + str(coordinates[j][0]) - if more_check == len(coordinates) - 1: - check = 2 - break - elif more_check > 0 and more_check != len(coordinates) - 1: - check = 3 - else: - check = 1 + if len(coordinates) == 0 or not all(len(pair) == 2 for pair in coordinates): + return "The program cannot work out a fitting polynomial." + + if len({tuple(pair) for pair in coordinates}) != len(coordinates): + return "The program cannot work out a fitting polynomial." - if len(coordinates) == 1 and coordinates[0][0] == 0: - check = 2 - solved = "x=0" - except Exception: - check = 3 + set_x = {x for x, _ in coordinates} + if len(set_x) == 1: + return "x=" + str(coordinates[0][0]) + + if len(set_x) != len(coordinates): + return "The program cannot work out a fitting polynomial." x = len(coordinates) - if check == 1: - count_of_line = 0 - matrix: list[list[float]] = [] - # put the x and x to the power values in a matrix - while count_of_line < x: - count_in_line = 0 - a = coordinates[count_of_line][0] - count_line: list[float] = [] - while count_in_line < x: - count_line.append(a ** (x - (count_in_line + 1))) - count_in_line += 1 - matrix.append(count_line) - count_of_line += 1 + count_of_line = 0 + matrix: list[list[float]] = [] + # put the x and x to the power values in a matrix + while count_of_line < x: + count_in_line = 0 + a = coordinates[count_of_line][0] + count_line: list[float] = [] + while count_in_line < x: + count_line.append(a ** (x - (count_in_line + 1))) + count_in_line += 1 + matrix.append(count_line) + count_of_line += 1 - count_of_line = 0 - # put the y values into a vector - vector: list[float] = [] - while count_of_line < x: - vector.append(coordinates[count_of_line][1]) - count_of_line += 1 + count_of_line = 0 + # put the y values into a vector + vector: list[float] = [] + while count_of_line < x: + vector.append(coordinates[count_of_line][1]) + count_of_line += 1 - count = 0 + count = 0 - while count < x: - zahlen = 0 - while zahlen < x: - if count == zahlen: - zahlen += 1 - if zahlen == x: - break - bruch = matrix[zahlen][count] / matrix[count][count] - for counting_columns, item in enumerate(matrix[count]): - # manipulating all the values in the matrix - matrix[zahlen][counting_columns] -= item * bruch - # manipulating the values in the vector - vector[zahlen] -= vector[count] * bruch + while count < x: + zahlen = 0 + while zahlen < x: + if count == zahlen: zahlen += 1 - count += 1 - - count = 0 - # make solutions - solution: list[str] = [] - while count < x: - solution.append(str(vector[count] / matrix[count][count])) - count += 1 + if zahlen == x: + break + bruch = matrix[zahlen][count] / matrix[count][count] + for counting_columns, item in enumerate(matrix[count]): + # manipulating all the values in the matrix + matrix[zahlen][counting_columns] -= item * bruch + # manipulating the values in the vector + vector[zahlen] -= vector[count] * bruch + zahlen += 1 + count += 1 - count = 0 - solved = "f(x)=" + count = 0 + # make solutions + solution: list[str] = [] + while count < x: + solution.append(str(vector[count] / matrix[count][count])) + count += 1 - while count < x: - remove_e: list[str] = solution[count].split("E") - if len(remove_e) > 1: - solution[count] = remove_e[0] + "*10^" + remove_e[1] - solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count]) - if count + 1 != x: - solved += "+" - count += 1 + count = 0 + solved = "f(x)=" - return solved + while count < x: + remove_e: list[str] = solution[count].split("E") + if len(remove_e) > 1: + solution[count] = remove_e[0] + "*10^" + remove_e[1] + solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count]) + if count + 1 != x: + solved += "+" + count += 1 - elif check == 2: - return solved - else: - return "The program cannot work out a fitting polynomial." + return solved if __name__ == "__main__": From 35774f6563bc1e750b44b98022767e96ab20b788 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 2 Nov 2022 21:22:25 +0300 Subject: [PATCH 6/8] Update linear_algebra/src/polynom_for_points.py Co-authored-by: Christian Clauss --- linear_algebra/src/polynom_for_points.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index 84b4bc770835..034057bb8bbe 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -32,7 +32,7 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: set_x = {x for x, _ in coordinates} if len(set_x) == 1: - return "x=" + str(coordinates[0][0]) + return f"x={coordinates[0][0]}" if len(set_x) != len(coordinates): return "The program cannot work out a fitting polynomial." From 0117eb1459f0aaf35246e37fa1d2a57474f1a30f Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Wed, 2 Nov 2022 21:22:56 +0300 Subject: [PATCH 7/8] Update linear_algebra/src/polynom_for_points.py Co-authored-by: Christian Clauss --- linear_algebra/src/polynom_for_points.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index 034057bb8bbe..af8006b8a466 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -91,7 +91,7 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: remove_e: list[str] = solution[count].split("E") if len(remove_e) > 1: solution[count] = remove_e[0] + "*10^" + remove_e[1] - solved += "x^" + str(x - (count + 1)) + "*" + str(solution[count]) + solved += f"x^{x - (count + 1)}*{solution[count]}" if count + 1 != x: solved += "+" count += 1 From 82381d520b196dc02d2dab872e78c3cf2c065ed0 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Wed, 2 Nov 2022 21:27:05 +0300 Subject: [PATCH 8/8] Fix --- linear_algebra/src/polynom_for_points.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linear_algebra/src/polynom_for_points.py b/linear_algebra/src/polynom_for_points.py index af8006b8a466..1d702deb1e99 100644 --- a/linear_algebra/src/polynom_for_points.py +++ b/linear_algebra/src/polynom_for_points.py @@ -90,7 +90,7 @@ def points_to_polynomial(coordinates: list[list[int]]) -> str: while count < x: remove_e: list[str] = solution[count].split("E") if len(remove_e) > 1: - solution[count] = remove_e[0] + "*10^" + remove_e[1] + solution[count] = f"{remove_e[0]}*10^{remove_e[1]}" solved += f"x^{x - (count + 1)}*{solution[count]}" if count + 1 != x: solved += "+"