From 3abb0b4c04f230f9f515d0dd2507c1991a3ffd7e Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Wed, 4 Oct 2023 20:47:39 +0530 Subject: [PATCH 01/20] Python mirror_formulae.py is added to the repository --- physics/mirror_formulae.py | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 physics/mirror_formulae.py diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py new file mode 100644 index 000000000000..25556928126f --- /dev/null +++ b/physics/mirror_formulae.py @@ -0,0 +1,87 @@ +""" +This module contains the functions to calculate the focal length, object distance and image distance of a mirror. + +The mirror formula is an equation that relates the object distance (u), image distance (v), and focal length (f) of a spherical mirror. +It is commonly used in optics to determine the position and characteristics of an image formed by a mirror. It is expressed using the formulae : + +------------------- +| 1/f = 1/v + 1/u | +------------------- + +Where, +f = Focal length of the spherical mirror (metre) +v = Image distance from the mirror (metre) +u = Object distance from the mirror (metre) + + +The signs of the distances are taken with respect to the sign convention. The sign convention is as follows: + 1) Object is always placed to the left of mirror + 2) Distances measured in the direction of the incident ray are positive and the distances measured in the direction opposite to that of the incident rays are negative. + 3) All distances are measured from the pole of the mirror. + + +There are a few assumptions that are made while using the mirror formulae. They are as follows: + 1) Thin Mirror: The mirror is assumed to be thin, meaning its thickness is negligible compared to its radius of curvature. This assumption allows us to treat the mirror as a two-dimensional surface. + 2) Spherical Mirror: The mirror is assumed to have a spherical shape. While this assumption may not hold exactly for all mirrors, it is a reasonable approximation for most practical purposes. + 3) Small Angles: The angles involved in the derivation are assumed to be small. This assumption allows us to use the small-angle approximation, where the tangent of a small angle is approximately equal to the angle itself. It simplifies the calculations and makes the derivation more manageable. + 4) Paraxial Rays: The mirror formula is derived using paraxial rays, which are rays that are close to the principal axis and make small angles with it. This assumption ensures that the rays are close enough to the principal axis, making the calculations more accurate. + 5) Reflection and Refraction Laws: The derivation assumes that the laws of reflection and refraction hold. These laws state that the angle of incidence is equal to the angle of reflection for reflection, and the incident and refracted rays lie in the same plane and obey Snell's law for refraction. + +(Description and Assumptions adapted from https://www.collegesearch.in/articles/mirror-formula-derivation) +(Sign Convention adapted from https://www.toppr.com/ask/content/concept/sign-convention-for-mirrors-210189/) + + +""" +def focal_length(distance_of_object : float , distance_of_image : float ) -> float: + """ + >>> focal_length(10, 20) + 6.666666666666667 + >>> focal_length(9.5, 6.7) + 3.929012346 + >>> focal_length(0, 20) + Traceback (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. + """ + + if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: + raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") + focal_length = 1/((1/distance_of_object) + (1/distance_of_image)) + return focal_length + +def object_distance(focal_length : float , distance_of_image : float ) -> float: + """ + >>> object_distance(30, 20) + -60 + >>> object_distance(10.5, 11.7) + 102.375 + >>> object_distance(90, 0) + Traceback (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. + """ + + if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: + raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") + object_distance = 1/((1/focal_length) - (1/distance_of_image)) + return object_distance + +def image_distance(distance_of_object : float , focal_length : float ) -> float: + """ + >>> image_distance(10, 40) + 13.33333333 + >>> image_distance(1.5, 6.7) + 1.932692308 + >>> image_distance(0, 0) + Traceback (most recent call last): + ... + ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. + """ + + if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: + raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") + image_distance = 1/((1/focal_length) + (1/distance_of_object)) + return image_distance + + + \ No newline at end of file From bc1942a29dc40a8f612981e09dec9583767d9f69 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Wed, 4 Oct 2023 21:31:55 +0530 Subject: [PATCH 02/20] Changes done after reading readme.md --- physics/mirror_formulae.py | 110 ++++++++++++++++++++++++------------- 1 file changed, 72 insertions(+), 38 deletions(-) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index 25556928126f..68e9b5cb90bf 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -1,11 +1,14 @@ """ -This module contains the functions to calculate the focal length, object distance and image distance of a mirror. +This module contains the functions to calculate the focal length, object distance +and image distance of a mirror. -The mirror formula is an equation that relates the object distance (u), image distance (v), and focal length (f) of a spherical mirror. -It is commonly used in optics to determine the position and characteristics of an image formed by a mirror. It is expressed using the formulae : +The mirror formula is an equation that relates the object distance (u), +image distance (v), and focal length (f) of a spherical mirror. +It is commonly used in optics to determine the position and characteristics +of an image formed by a mirror. It is expressed using the formulae : ------------------- -| 1/f = 1/v + 1/u | +| 1/f = 1/v + 1/u | ------------------- Where, @@ -14,25 +17,48 @@ u = Object distance from the mirror (metre) -The signs of the distances are taken with respect to the sign convention. The sign convention is as follows: +The signs of the distances are taken with respect to the sign convention. +The sign convention is as follows: 1) Object is always placed to the left of mirror - 2) Distances measured in the direction of the incident ray are positive and the distances measured in the direction opposite to that of the incident rays are negative. + 2) Distances measured in the direction of the incident ray are positive + and the distances measured in the direction opposite to that of the incident + rays are negative. 3) All distances are measured from the pole of the mirror. -There are a few assumptions that are made while using the mirror formulae. They are as follows: - 1) Thin Mirror: The mirror is assumed to be thin, meaning its thickness is negligible compared to its radius of curvature. This assumption allows us to treat the mirror as a two-dimensional surface. - 2) Spherical Mirror: The mirror is assumed to have a spherical shape. While this assumption may not hold exactly for all mirrors, it is a reasonable approximation for most practical purposes. - 3) Small Angles: The angles involved in the derivation are assumed to be small. This assumption allows us to use the small-angle approximation, where the tangent of a small angle is approximately equal to the angle itself. It simplifies the calculations and makes the derivation more manageable. - 4) Paraxial Rays: The mirror formula is derived using paraxial rays, which are rays that are close to the principal axis and make small angles with it. This assumption ensures that the rays are close enough to the principal axis, making the calculations more accurate. - 5) Reflection and Refraction Laws: The derivation assumes that the laws of reflection and refraction hold. These laws state that the angle of incidence is equal to the angle of reflection for reflection, and the incident and refracted rays lie in the same plane and obey Snell's law for refraction. +There are a few assumptions that are made while using the mirror formulae. +They are as follows: + 1) Thin Mirror: The mirror is assumed to be thin, meaning its thickness is + negligible compared to its radius of curvature. This assumption allows + us to treat the mirror as a two-dimensional surface. + 2) Spherical Mirror: The mirror is assumed to have a spherical shape. While this + assumption may not hold exactly for all mirrors, it is a reasonable approximation + for most practical purposes. + 3) Small Angles: The angles involved in the derivation are assumed to be small. + This assumption allows us to use the small-angle approximation, where the tangent + of a small angle is approximately equal to the angle itself. It simplifies the + calculations and makes the derivation more manageable. + 4) Paraxial Rays: The mirror formula is derived using paraxial rays, which are + rays that are close to the principal axis and make small angles with it. This + assumption ensures that the rays are close enough to the principal axis, making the + calculations more accurate. + 5) Reflection and Refraction Laws: The derivation assumes that the laws of + reflection and refraction hold. + These laws state that the angle of incidence is equal to the angle of reflection + for reflection, and the incident and refracted rays lie in the same plane and + obey Snell's law for refraction. -(Description and Assumptions adapted from https://www.collegesearch.in/articles/mirror-formula-derivation) -(Sign Convention adapted from https://www.toppr.com/ask/content/concept/sign-convention-for-mirrors-210189/) +(Description and Assumptions adapted from +https://www.collegesearch.in/articles/mirror-formula-derivation) + +(Sign Convention adapted from +https://www.toppr.com/ask/content/concept/sign-convention-for-mirrors-210189/) """ -def focal_length(distance_of_object : float , distance_of_image : float ) -> float: + + +def focal_length(distance_of_object: float, distance_of_image: float) -> float: """ >>> focal_length(10, 20) 6.666666666666667 @@ -41,15 +67,19 @@ def focal_length(distance_of_object : float , distance_of_image : float ) -> flo >>> focal_length(0, 20) Traceback (most recent call last): ... - ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. - """ - - if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: - raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") - focal_length = 1/((1/distance_of_object) + (1/distance_of_image)) + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + + if distance_of_object == 0 or distance_of_image == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + focal_length = 1 / ((1 / distance_of_object) + (1 / distance_of_image)) return focal_length -def object_distance(focal_length : float , distance_of_image : float ) -> float: + +def object_distance(focal_length: float, distance_of_image: float) -> float: """ >>> object_distance(30, 20) -60 @@ -58,15 +88,19 @@ def object_distance(focal_length : float , distance_of_image : float ) -> float: >>> object_distance(90, 0) Traceback (most recent call last): ... - ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. - """ - - if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: - raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") - object_distance = 1/((1/focal_length) - (1/distance_of_image)) + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + + if distance_of_image == 0 or focal_length == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + object_distance = 1 / ((1 / focal_length) - (1 / distance_of_image)) return object_distance -def image_distance(distance_of_object : float , focal_length : float ) -> float: + +def image_distance(distance_of_object: float, focal_length: float) -> float: """ >>> image_distance(10, 40) 13.33333333 @@ -75,13 +109,13 @@ def image_distance(distance_of_object : float , focal_length : float ) -> float: >>> image_distance(0, 0) Traceback (most recent call last): ... - ValueError: Invalid inputs. Enter non zero values with respect to the sign convention. - """ - - if distance_of_object == 0 or distance_of_image == 0 or focal_length == 0: - raise ValueError("Invalid inputs. Enter non zero values with respect to the sign convention.") - image_distance = 1/((1/focal_length) + (1/distance_of_object)) + ValueError: Invalid inputs. Enter non zero values with respect + to the sign convention. + """ + + if distance_of_object == 0 or focal_length == 0: + raise ValueError( + "Invalid inputs. Enter non zero values with respect to the sign convention." + ) + image_distance = 1 / ((1 / focal_length) + (1 / distance_of_object)) return image_distance - - - \ No newline at end of file From d0979d36bc656ce3671fbc1522cba5ef7a4cf26d Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Thu, 5 Oct 2023 08:00:36 +0530 Subject: [PATCH 03/20] Changes for running doctest on all platforms --- physics/mirror_formulae.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index 68e9b5cb90bf..e9b82fe3e84f 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -57,13 +57,13 @@ """ - +from math import isclose def focal_length(distance_of_object: float, distance_of_image: float) -> float: """ - >>> focal_length(10, 20) - 6.666666666666667 - >>> focal_length(9.5, 6.7) - 3.929012346 + >>> isclose(focal_length(10, 20), 6.666666666666667) + True + >>> isclose(focal_length(9.5, 6.7), 3.929012346) + True >>> focal_length(0, 20) Traceback (most recent call last): ... @@ -81,10 +81,10 @@ def focal_length(distance_of_object: float, distance_of_image: float) -> float: def object_distance(focal_length: float, distance_of_image: float) -> float: """ - >>> object_distance(30, 20) - -60 - >>> object_distance(10.5, 11.7) - 102.375 + >>> isclose(object_distance(30, 20), -60.0) + True + >>> isclose(object_distance(10.5, 11.7), 102.375) + True >>> object_distance(90, 0) Traceback (most recent call last): ... @@ -100,12 +100,12 @@ def object_distance(focal_length: float, distance_of_image: float) -> float: return object_distance -def image_distance(distance_of_object: float, focal_length: float) -> float: +def image_distance(focal_length: float, distance_of_object: float) -> float: """ - >>> image_distance(10, 40) - 13.33333333 - >>> image_distance(1.5, 6.7) - 1.932692308 + >>> isclose(image_distance(10, 40), 13.33333333) + True + >>> isclose(image_distance(1.5, 6.7), 1.932692308) + True >>> image_distance(0, 0) Traceback (most recent call last): ... @@ -117,5 +117,5 @@ def image_distance(distance_of_object: float, focal_length: float) -> float: raise ValueError( "Invalid inputs. Enter non zero values with respect to the sign convention." ) - image_distance = 1 / ((1 / focal_length) + (1 / distance_of_object)) + image_distance = 1 / ((1 / focal_length) - (1 / distance_of_object)) return image_distance From e5f2d76ef48721e71993e4b491c4bb4ce23f74c0 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 02:31:19 +0000 Subject: [PATCH 04/20] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- physics/mirror_formulae.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index e9b82fe3e84f..27d25220b781 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -58,6 +58,8 @@ """ from math import isclose + + def focal_length(distance_of_object: float, distance_of_image: float) -> float: """ >>> isclose(focal_length(10, 20), 6.666666666666667) From 0ed896b61b9b7d5d8a79d9062d0b92d65774625e Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Thu, 5 Oct 2023 09:12:18 +0530 Subject: [PATCH 05/20] Change 2 for Doctests --- physics/mirror_formulae.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index e9b82fe3e84f..f1b4ac2c7baf 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -57,11 +57,13 @@ """ -from math import isclose + def focal_length(distance_of_object: float, distance_of_image: float) -> float: """ - >>> isclose(focal_length(10, 20), 6.666666666666667) + >>> from math import isclose + >>> isclose(focal_length(10, 20), 6.66666666666666) True + >>> from math import isclose >>> isclose(focal_length(9.5, 6.7), 3.929012346) True >>> focal_length(0, 20) @@ -81,8 +83,10 @@ def focal_length(distance_of_object: float, distance_of_image: float) -> float: def object_distance(focal_length: float, distance_of_image: float) -> float: """ + >>> from math import isclose >>> isclose(object_distance(30, 20), -60.0) True + >>> from math import isclose >>> isclose(object_distance(10.5, 11.7), 102.375) True >>> object_distance(90, 0) @@ -102,8 +106,10 @@ def object_distance(focal_length: float, distance_of_image: float) -> float: def image_distance(focal_length: float, distance_of_object: float) -> float: """ + >>> from math import isclose >>> isclose(image_distance(10, 40), 13.33333333) True + >>> from math import isclose >>> isclose(image_distance(1.5, 6.7), 1.932692308) True >>> image_distance(0, 0) From 8affc05a9c19ea774dcad69c8a0f18c6d33ba250 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Thu, 5 Oct 2023 09:19:51 +0530 Subject: [PATCH 06/20] Changes for doctest 2 --- physics/mirror_formulae.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index 07715172712d..f1b4ac2c7baf 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -57,11 +57,6 @@ """ -<<<<<<< HEAD -======= -from math import isclose - ->>>>>>> e5f2d76ef48721e71993e4b491c4bb4ce23f74c0 def focal_length(distance_of_object: float, distance_of_image: float) -> float: """ From e250edebc922d81a10f97ac25743fce53f2a7eca Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 5 Oct 2023 03:50:31 +0000 Subject: [PATCH 07/20] updating DIRECTORY.md --- DIRECTORY.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 696a059bb4c8..5f23cbd6c922 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -170,6 +170,7 @@ ## Data Structures * Arrays + * [Median Two Array](data_structures/arrays/median_two_array.py) * [Permutations](data_structures/arrays/permutations.py) * [Prefix Sum](data_structures/arrays/prefix_sum.py) * [Product Sum](data_structures/arrays/product_sum.py) @@ -185,6 +186,7 @@ * [Diff Views Of Binary Tree](data_structures/binary_tree/diff_views_of_binary_tree.py) * [Distribute Coins](data_structures/binary_tree/distribute_coins.py) * [Fenwick Tree](data_structures/binary_tree/fenwick_tree.py) + * [Flatten Binarytree To Linkedlist](data_structures/binary_tree/flatten_binarytree_to_linkedlist.py) * [Inorder Tree Traversal 2022](data_structures/binary_tree/inorder_tree_traversal_2022.py) * [Is Bst](data_structures/binary_tree/is_bst.py) * [Lazy Segment Tree](data_structures/binary_tree/lazy_segment_tree.py) @@ -324,6 +326,7 @@ * [Longest Common Substring](dynamic_programming/longest_common_substring.py) * [Longest Increasing Subsequence](dynamic_programming/longest_increasing_subsequence.py) * [Longest Increasing Subsequence O(Nlogn)](dynamic_programming/longest_increasing_subsequence_o(nlogn).py) + * [Longest Palindromic Subsequence](dynamic_programming/longest_palindromic_subsequence.py) * [Longest Sub Array](dynamic_programming/longest_sub_array.py) * [Matrix Chain Order](dynamic_programming/matrix_chain_order.py) * [Max Non Adjacent Sum](dynamic_programming/max_non_adjacent_sum.py) @@ -539,6 +542,7 @@ * [Average Mode](maths/average_mode.py) * [Bailey Borwein Plouffe](maths/bailey_borwein_plouffe.py) * [Basic Maths](maths/basic_maths.py) + * [Bell Numbers](maths/bell_numbers.py) * [Binary Exp Mod](maths/binary_exp_mod.py) * [Binary Exponentiation](maths/binary_exponentiation.py) * [Binary Exponentiation 3](maths/binary_exponentiation_3.py) @@ -690,6 +694,7 @@ * [Matrix Class](matrix/matrix_class.py) * [Matrix Operation](matrix/matrix_operation.py) * [Max Area Of Island](matrix/max_area_of_island.py) + * [Median Matrix](matrix/median_matrix.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) @@ -708,8 +713,8 @@ * Activation Functions * [Exponential Linear Unit](neural_network/activation_functions/exponential_linear_unit.py) * [Leaky Rectified Linear Unit](neural_network/activation_functions/leaky_rectified_linear_unit.py) - * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Rectified Linear Unit](neural_network/activation_functions/rectified_linear_unit.py) + * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Perceptron](neural_network/perceptron.py) @@ -756,9 +761,11 @@ * [Kinetic Energy](physics/kinetic_energy.py) * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [Malus Law](physics/malus_law.py) + * [Mirror Formulae](physics/mirror_formulae.py) * [N Body Simulation](physics/n_body_simulation.py) * [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py) * [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py) + * [Photoelectric Effect](physics/photoelectric_effect.py) * [Potential Energy](physics/potential_energy.py) * [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py) * [Shear Stress](physics/shear_stress.py) From c79e13270ac53dd99fadf7c943912a38ddeb7398 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Thu, 5 Oct 2023 12:49:45 +0530 Subject: [PATCH 08/20] Doctest whitespace error rectification to mirror_formulae.py --- physics/mirror_formulae.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/physics/mirror_formulae.py b/physics/mirror_formulae.py index f1b4ac2c7baf..7efc52438140 100644 --- a/physics/mirror_formulae.py +++ b/physics/mirror_formulae.py @@ -66,7 +66,7 @@ def focal_length(distance_of_object: float, distance_of_image: float) -> float: >>> from math import isclose >>> isclose(focal_length(9.5, 6.7), 3.929012346) True - >>> focal_length(0, 20) + >>> focal_length(0, 20) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... ValueError: Invalid inputs. Enter non zero values with respect @@ -89,7 +89,7 @@ def object_distance(focal_length: float, distance_of_image: float) -> float: >>> from math import isclose >>> isclose(object_distance(10.5, 11.7), 102.375) True - >>> object_distance(90, 0) + >>> object_distance(90, 0) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... ValueError: Invalid inputs. Enter non zero values with respect @@ -112,7 +112,7 @@ def image_distance(focal_length: float, distance_of_object: float) -> float: >>> from math import isclose >>> isclose(image_distance(1.5, 6.7), 1.932692308) True - >>> image_distance(0, 0) + >>> image_distance(0, 0) # doctest: +NORMALIZE_WHITESPACE Traceback (most recent call last): ... ValueError: Invalid inputs. Enter non zero values with respect From 5355c9727a5574c6811a79b5e72a17f89dc5e73f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 5 Oct 2023 07:44:59 +0000 Subject: [PATCH 09/20] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index 5f23cbd6c922..b0ba3c3852da 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -469,6 +469,7 @@ * [Djb2](hashes/djb2.py) * [Elf](hashes/elf.py) * [Enigma Machine](hashes/enigma_machine.py) + * [Fletcher16](hashes/fletcher16.py) * [Hamming Code](hashes/hamming_code.py) * [Luhn](hashes/luhn.py) * [Md5](hashes/md5.py) From a749a2b3e3932831f7ea3ff8c505eec756cfb279 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Thu, 5 Oct 2023 22:40:29 +0530 Subject: [PATCH 10/20] Adding Thermodynamic Work Done Formulae --- physics/thermodynamics_work_done_formulae.py | 229 +++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 physics/thermodynamics_work_done_formulae.py diff --git a/physics/thermodynamics_work_done_formulae.py b/physics/thermodynamics_work_done_formulae.py new file mode 100644 index 000000000000..850da9426313 --- /dev/null +++ b/physics/thermodynamics_work_done_formulae.py @@ -0,0 +1,229 @@ +""" +This module contains the functions to calculate the work done in various +thermodynamic processes. +Work done by a system is defined as the quantity of energy exchanged between a +system and its surroundings. It is governed by external factors such as an external +force, pressure or volume or change in temperature etc. +In thermodynamics, the work is referred by the pressure-volume relationship of a +gaseous substance. The work done by a system is positive if the system expands and +negative if the system contracts. The work done by a system is given by default is +given by the formula: + +------------------- +| W = -PΔV | +------------------- + +Where, +W = Work done by/on the system (Joule) +P = Pressure (Pascal) +ΔV = Change in Volume (m^3) [Final Volume - Initial Volume] + +The work done by a system can be calculated in various ways depending +on the type of process. The different types of processes are as follows: + + 1) Irreversible Process: A process that cannot be reversed to its + initial state by an infinitesimal change in an external parameter + is called an irreversible process. The work done in an irreversible + process is given by the formula: + + ------------------------ + | W = -(Pext)ΔV | + ------------------------ + + Where, + W = Work done by/on the system (Joule) + Pext = External Pressure (Pascal) + ΔV = Change in Volume (m^3) [Final Volume - Initial Volume] + + + 2) Isothermal Reversible Process: A process that can be reversed to + its initial state by an infinitesimal change in an external parameter + is called an isothermal reversible process. The work done in an + isothermal reversible process is given by the formula: + + ------------------------------ + | W = -nRTln(Vf/Vi) | + ------------------------------ + + Where, + W = Work done by/on the system (Joule) + n = Number of moles (mol) + R = Universal Gas Constant (8.31446261815324 J/(mol K)) + T = Temperature (Kelvin) + Vf = Final Volume (m^3) + Vi = Initial Volume (m^3) + + or by the formula: + + ------------------------------ + | W = -nrtln(Pi/Pf) | + ------------------------------ + + Where, + W = Work done by/on the system (Joule) + n = Number of moles (mol) + R = Universal Gas Constant (8.31446261815324 J/(mol K)) + T = Temperature (Kelvin) + Pf = Final Pressure (Pascal) + Pi = Initial Pressure (Pascal) + + 3) Adiabatic Process: A process that occurs without any heat exchange + between the system and its surroundings is called an adiabatic process. + The work done in an adiabatic process is given by the formula: + + --------------------------------- + | W = nR(Tf - Ti)/(1-γ) | + --------------------------------- + + Where, + W = Work done by/on the system (Joule) + n = Number of moles (mol) + R = Universal Gas Constant (8.31446261815324 J/(mol K)) + Tf = Final Temperature (Kelvin) + Ti = Initial Temperature (Kelvin) + γ = Poisson's Ratio (Dimensionless) + + +(Definitions and Types adapted from +https://www.w3schools.blog/work-done-in-thermodynamics) +(Formulaes adapted from +https://byjus.com/jee/thermodynamics-for-iit-jee/#:~:text=Work%20Done%20in%20Different%20Thermodynamics%20Processes) + +""" + + +def irreversible_work_done( + pressure_external: float, volume_initial: float, volume_final: float +) -> float: + """ + This function calculates the work done in an irreversible process. + + >>> from math import isclose + >>> isclose(irreversible_work_done(1, 110, 112), -2,\ + abs_tol = 1) + True + >>> from math import isclose + >>> isclose(irreversible_work_done(2.5, 312, 233.7), \ + 195.75, abs_tol = 1) + True + >>> irreversible_work_done(4, 2, 2) + 0 + """ + work_done = 0 - (pressure_external * (volume_final - volume_initial)) + return work_done + + +def isothermal_reversible_work_done_volume( + number_of_moles: float, + temperature: float, + volume_initial: float, + volume_final: float, +) -> float: + """ + This function calculates the work done in an isothermal reversible + process using the Initial and Final Volume. + + >>> from math import isclose + >>> isclose(isothermal_reversible_work_done_volume(1, 100, 1, 2),\ + -250.2,abs_tol = 1) + True + >>> from math import isclose + >>> isclose(isothermal_reversible_work_done_volume(2.5, 320, 32, 233.7),\ + -5743.6, \ + abs_tol =1) + True + >>> isothermal_reversible_work_done_volume(4, 200, 2, 2) + 0.0 + >>> isothermal_reversible_work_done_volume(4, 200, 2, 0) \ + # doctest: +NORMALIZE_WHITESPACE + Traceback (most recent call last): + ... + ValueError: Volume can not be zero + """ + import math + + if volume_initial == 0 or volume_final == 0: + raise ValueError("Volume can not be zero") + r = 8.31446261815324 + work_done = 0 - ( + (number_of_moles * r * temperature * math.log(volume_final / volume_initial)) + / 2.303 + ) + return work_done + + +def isothermal_reversible_work_done_pressure( + number_of_moles: float, + temperature: float, + pressure_initial: float, + pressure_final: float, +) -> float: + """ + This function calculates the work done in an isothermal reversible + process using the Initial and Final Pressures. + + >>> from math import isclose + >>> isclose(isothermal_reversible_work_done_pressure(9, 111, 31, 42),\ + -1095.469667 ,abs_tol = 1) + True + >>> from math import isclose + >>> isclose(isothermal_reversible_work_done_pressure(10, 335.2, 32, 133.7),\ + -17303.6 , abs_tol = 1) + True + >>> isothermal_reversible_work_done_pressure(4, 230, 10, 10) + 0.0 + >>> isothermal_reversible_work_done_pressure(4, 200, 10, 0)\ + # doctest: +NORMALIZE_WHITESPACE + Traceback (most recent call last): + ... + ValueError: Pressure can not be zero + """ + import math + + if pressure_final == 0 or pressure_initial == 0: + raise ValueError("Pressure can not be zero") + r = 8.31446261815324 + work_done = 0 - ( + ( + number_of_moles + * r + * temperature + * math.log(pressure_final / pressure_initial) + ) + / 2.303 + ) + return work_done + + +def adiabatic_work_done( + number_of_moles: float, + poisson_ratio: float, + initial_temperature: float, + final_temperature: float, +) -> float: + """ + This function calculates the work done in an adiabatic process. + + >>> from math import isclose + >>> isclose(adiabatic_work_done(1, 0.5, 100, 200), 1662.88,\ + abs_tol = 1) + True + >>> from math import isclose + >>> isclose(adiabatic_work_done(2.5, 0.7, 320, 233.7),\ + -5979.439333333333, abs_tol = 1) + True + >>> adiabatic_work_done(4, 0.9, 200, 200) + 0.0 + >>> adiabatic_work_done(4, 1, 200, 200)\ + # doctest: +NORMALIZE_WHITESPACE + Traceback (most recent call last): + ... + ValueError: Poisson's Ratio cannot be equal to 1 + """ + if poisson_ratio == 1: + raise ValueError("Poisson's Ratio cannot be equal to 1") + r = 8.31446261815324 + work_done = (number_of_moles * r * (final_temperature - initial_temperature)) / ( + 1 - poisson_ratio + ) + return work_done From 6c7765c56da4fb7c2ec4521d20ae2730b1699628 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Fri, 6 Oct 2023 08:28:54 +0530 Subject: [PATCH 11/20] Work done on/by body in a thermodynamic setting --- physics/thermodynamics_work_done_formulae.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/physics/thermodynamics_work_done_formulae.py b/physics/thermodynamics_work_done_formulae.py index 850da9426313..2fe474f3c2f9 100644 --- a/physics/thermodynamics_work_done_formulae.py +++ b/physics/thermodynamics_work_done_formulae.py @@ -39,7 +39,7 @@ 2) Isothermal Reversible Process: A process that can be reversed to its initial state by an infinitesimal change in an external parameter is called an isothermal reversible process. The work done in an - isothermal reversible process is given by the formula: + isothermal reversible process is given by formula: ------------------------------ | W = -nRTln(Vf/Vi) | From 96ed5c1ed3b845a5ff8f8199da6f9780f2a38784 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Fri, 6 Oct 2023 03:00:00 +0000 Subject: [PATCH 12/20] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index a975b9264be0..eb27ad530f80 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -781,6 +781,7 @@ * [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py) * [Shear Stress](physics/shear_stress.py) * [Speed Of Sound](physics/speed_of_sound.py) + * [Thermodynamics Work Done Formulae](physics/thermodynamics_work_done_formulae.py) ## Project Euler * Problem 001 From 873fe877339148df69ae0203f57c4b743ce2d582 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 8 Oct 2023 13:39:43 +0000 Subject: [PATCH 13/20] updating DIRECTORY.md --- DIRECTORY.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index eb27ad530f80..ed3df97f1e2f 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -101,6 +101,7 @@ * [Diffie Hellman](ciphers/diffie_hellman.py) * [Elgamal Key Generator](ciphers/elgamal_key_generator.py) * [Enigma Machine2](ciphers/enigma_machine2.py) + * [Fractionated Morse Cipher](ciphers/fractionated_morse_cipher.py) * [Hill Cipher](ciphers/hill_cipher.py) * [Mixed Keyword Cypher](ciphers/mixed_keyword_cypher.py) * [Mono Alphabetic Ciphers](ciphers/mono_alphabetic_ciphers.py) @@ -352,6 +353,7 @@ * [Smith Waterman](dynamic_programming/smith_waterman.py) * [Subset Generation](dynamic_programming/subset_generation.py) * [Sum Of Subset](dynamic_programming/sum_of_subset.py) + * [Trapped Water](dynamic_programming/trapped_water.py) * [Tribonacci](dynamic_programming/tribonacci.py) * [Viterbi](dynamic_programming/viterbi.py) * [Word Break](dynamic_programming/word_break.py) @@ -360,6 +362,7 @@ * [Apparent Power](electronics/apparent_power.py) * [Builtin Voltage](electronics/builtin_voltage.py) * [Carrier Concentration](electronics/carrier_concentration.py) + * [Charging Capacitor](electronics/charging_capacitor.py) * [Circular Convolution](electronics/circular_convolution.py) * [Coulombs Law](electronics/coulombs_law.py) * [Electric Conductivity](electronics/electric_conductivity.py) @@ -466,6 +469,7 @@ * [Test Min Spanning Tree Prim](graphs/tests/test_min_spanning_tree_prim.py) ## Greedy Methods + * [Fractional Cover Problem](greedy_methods/fractional_cover_problem.py) * [Fractional Knapsack](greedy_methods/fractional_knapsack.py) * [Fractional Knapsack 2](greedy_methods/fractional_knapsack_2.py) * [Gas Station](greedy_methods/gas_station.py) @@ -588,7 +592,6 @@ * [Find Min](maths/find_min.py) * [Floor](maths/floor.py) * [Gamma](maths/gamma.py) - * [Gamma Recursive](maths/gamma_recursive.py) * [Gaussian](maths/gaussian.py) * [Gaussian Error Linear Unit](maths/gaussian_error_linear_unit.py) * [Gcd Of N Numbers](maths/gcd_of_n_numbers.py) @@ -723,9 +726,11 @@ * Activation Functions * [Exponential Linear Unit](neural_network/activation_functions/exponential_linear_unit.py) * [Leaky Rectified Linear Unit](neural_network/activation_functions/leaky_rectified_linear_unit.py) + * [Mish](neural_network/activation_functions/mish.py) * [Rectified Linear Unit](neural_network/activation_functions/rectified_linear_unit.py) * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Sigmoid Linear Unit](neural_network/activation_functions/sigmoid_linear_unit.py) + * [Softplus](neural_network/activation_functions/softplus.py) * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Perceptron](neural_network/perceptron.py) @@ -748,6 +753,7 @@ * [Linear Congruential Generator](other/linear_congruential_generator.py) * [Lru Cache](other/lru_cache.py) * [Magicdiamondpattern](other/magicdiamondpattern.py) + * [Majority Vote Algorithm](other/majority_vote_algorithm.py) * [Maximum Subsequence](other/maximum_subsequence.py) * [Nested Brackets](other/nested_brackets.py) * [Number Container System](other/number_container_system.py) From 489b890f186da11ae5237d4a8a4f6093343d699d Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Sun, 8 Oct 2023 20:22:44 +0530 Subject: [PATCH 14/20] Doctest adiition to binary_exponentiation_3.py --- maths/binary_exponentiation_3.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/maths/binary_exponentiation_3.py b/maths/binary_exponentiation_3.py index 9cd143e09207..6ac537f32dee 100644 --- a/maths/binary_exponentiation_3.py +++ b/maths/binary_exponentiation_3.py @@ -12,6 +12,16 @@ def b_expo(a: int, b: int) -> int: + """ + >>> b_expo(2, 10) + 1024 + >>> b_expo(9, 0) + 1 + >>> b_expo(0, 12) + 0 + >>> b_expo(4,12) + 16777216 + """ res = 1 while b > 0: if b & 1: @@ -24,6 +34,16 @@ def b_expo(a: int, b: int) -> int: def b_expo_mod(a: int, b: int, c: int) -> int: + """ + >>> b_expo_mod(2, 10, 1000000007) + 1024 + >>> b_expo_mod(11,13,19) + 11 + >>> b_expo_mod(0, 19, 20) + 0 + >>> b_expo_mod(15, 5 , 4) + 3 + """ res = 1 while b > 0: if b & 1: From 0be0051876c490fe5d850ca8c38ca7c1a386f0c8 Mon Sep 17 00:00:00 2001 From: Vipin Karthic Date: Sun, 8 Oct 2023 20:28:03 +0530 Subject: [PATCH 15/20] Change 1 --- physics/thermodynamics_work_done_formulae.py | 229 ------------------- 1 file changed, 229 deletions(-) delete mode 100644 physics/thermodynamics_work_done_formulae.py diff --git a/physics/thermodynamics_work_done_formulae.py b/physics/thermodynamics_work_done_formulae.py deleted file mode 100644 index 2fe474f3c2f9..000000000000 --- a/physics/thermodynamics_work_done_formulae.py +++ /dev/null @@ -1,229 +0,0 @@ -""" -This module contains the functions to calculate the work done in various -thermodynamic processes. -Work done by a system is defined as the quantity of energy exchanged between a -system and its surroundings. It is governed by external factors such as an external -force, pressure or volume or change in temperature etc. -In thermodynamics, the work is referred by the pressure-volume relationship of a -gaseous substance. The work done by a system is positive if the system expands and -negative if the system contracts. The work done by a system is given by default is -given by the formula: - -------------------- -| W = -PΔV | -------------------- - -Where, -W = Work done by/on the system (Joule) -P = Pressure (Pascal) -ΔV = Change in Volume (m^3) [Final Volume - Initial Volume] - -The work done by a system can be calculated in various ways depending -on the type of process. The different types of processes are as follows: - - 1) Irreversible Process: A process that cannot be reversed to its - initial state by an infinitesimal change in an external parameter - is called an irreversible process. The work done in an irreversible - process is given by the formula: - - ------------------------ - | W = -(Pext)ΔV | - ------------------------ - - Where, - W = Work done by/on the system (Joule) - Pext = External Pressure (Pascal) - ΔV = Change in Volume (m^3) [Final Volume - Initial Volume] - - - 2) Isothermal Reversible Process: A process that can be reversed to - its initial state by an infinitesimal change in an external parameter - is called an isothermal reversible process. The work done in an - isothermal reversible process is given by formula: - - ------------------------------ - | W = -nRTln(Vf/Vi) | - ------------------------------ - - Where, - W = Work done by/on the system (Joule) - n = Number of moles (mol) - R = Universal Gas Constant (8.31446261815324 J/(mol K)) - T = Temperature (Kelvin) - Vf = Final Volume (m^3) - Vi = Initial Volume (m^3) - - or by the formula: - - ------------------------------ - | W = -nrtln(Pi/Pf) | - ------------------------------ - - Where, - W = Work done by/on the system (Joule) - n = Number of moles (mol) - R = Universal Gas Constant (8.31446261815324 J/(mol K)) - T = Temperature (Kelvin) - Pf = Final Pressure (Pascal) - Pi = Initial Pressure (Pascal) - - 3) Adiabatic Process: A process that occurs without any heat exchange - between the system and its surroundings is called an adiabatic process. - The work done in an adiabatic process is given by the formula: - - --------------------------------- - | W = nR(Tf - Ti)/(1-γ) | - --------------------------------- - - Where, - W = Work done by/on the system (Joule) - n = Number of moles (mol) - R = Universal Gas Constant (8.31446261815324 J/(mol K)) - Tf = Final Temperature (Kelvin) - Ti = Initial Temperature (Kelvin) - γ = Poisson's Ratio (Dimensionless) - - -(Definitions and Types adapted from -https://www.w3schools.blog/work-done-in-thermodynamics) -(Formulaes adapted from -https://byjus.com/jee/thermodynamics-for-iit-jee/#:~:text=Work%20Done%20in%20Different%20Thermodynamics%20Processes) - -""" - - -def irreversible_work_done( - pressure_external: float, volume_initial: float, volume_final: float -) -> float: - """ - This function calculates the work done in an irreversible process. - - >>> from math import isclose - >>> isclose(irreversible_work_done(1, 110, 112), -2,\ - abs_tol = 1) - True - >>> from math import isclose - >>> isclose(irreversible_work_done(2.5, 312, 233.7), \ - 195.75, abs_tol = 1) - True - >>> irreversible_work_done(4, 2, 2) - 0 - """ - work_done = 0 - (pressure_external * (volume_final - volume_initial)) - return work_done - - -def isothermal_reversible_work_done_volume( - number_of_moles: float, - temperature: float, - volume_initial: float, - volume_final: float, -) -> float: - """ - This function calculates the work done in an isothermal reversible - process using the Initial and Final Volume. - - >>> from math import isclose - >>> isclose(isothermal_reversible_work_done_volume(1, 100, 1, 2),\ - -250.2,abs_tol = 1) - True - >>> from math import isclose - >>> isclose(isothermal_reversible_work_done_volume(2.5, 320, 32, 233.7),\ - -5743.6, \ - abs_tol =1) - True - >>> isothermal_reversible_work_done_volume(4, 200, 2, 2) - 0.0 - >>> isothermal_reversible_work_done_volume(4, 200, 2, 0) \ - # doctest: +NORMALIZE_WHITESPACE - Traceback (most recent call last): - ... - ValueError: Volume can not be zero - """ - import math - - if volume_initial == 0 or volume_final == 0: - raise ValueError("Volume can not be zero") - r = 8.31446261815324 - work_done = 0 - ( - (number_of_moles * r * temperature * math.log(volume_final / volume_initial)) - / 2.303 - ) - return work_done - - -def isothermal_reversible_work_done_pressure( - number_of_moles: float, - temperature: float, - pressure_initial: float, - pressure_final: float, -) -> float: - """ - This function calculates the work done in an isothermal reversible - process using the Initial and Final Pressures. - - >>> from math import isclose - >>> isclose(isothermal_reversible_work_done_pressure(9, 111, 31, 42),\ - -1095.469667 ,abs_tol = 1) - True - >>> from math import isclose - >>> isclose(isothermal_reversible_work_done_pressure(10, 335.2, 32, 133.7),\ - -17303.6 , abs_tol = 1) - True - >>> isothermal_reversible_work_done_pressure(4, 230, 10, 10) - 0.0 - >>> isothermal_reversible_work_done_pressure(4, 200, 10, 0)\ - # doctest: +NORMALIZE_WHITESPACE - Traceback (most recent call last): - ... - ValueError: Pressure can not be zero - """ - import math - - if pressure_final == 0 or pressure_initial == 0: - raise ValueError("Pressure can not be zero") - r = 8.31446261815324 - work_done = 0 - ( - ( - number_of_moles - * r - * temperature - * math.log(pressure_final / pressure_initial) - ) - / 2.303 - ) - return work_done - - -def adiabatic_work_done( - number_of_moles: float, - poisson_ratio: float, - initial_temperature: float, - final_temperature: float, -) -> float: - """ - This function calculates the work done in an adiabatic process. - - >>> from math import isclose - >>> isclose(adiabatic_work_done(1, 0.5, 100, 200), 1662.88,\ - abs_tol = 1) - True - >>> from math import isclose - >>> isclose(adiabatic_work_done(2.5, 0.7, 320, 233.7),\ - -5979.439333333333, abs_tol = 1) - True - >>> adiabatic_work_done(4, 0.9, 200, 200) - 0.0 - >>> adiabatic_work_done(4, 1, 200, 200)\ - # doctest: +NORMALIZE_WHITESPACE - Traceback (most recent call last): - ... - ValueError: Poisson's Ratio cannot be equal to 1 - """ - if poisson_ratio == 1: - raise ValueError("Poisson's Ratio cannot be equal to 1") - r = 8.31446261815324 - work_done = (number_of_moles * r * (final_temperature - initial_temperature)) / ( - 1 - poisson_ratio - ) - return work_done From b71c1b9020e19a41c060ed6e5ae1ccf1c7b9b44f Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 8 Oct 2023 14:58:52 +0000 Subject: [PATCH 16/20] updating DIRECTORY.md --- DIRECTORY.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index ed3df97f1e2f..ffc83292c68d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -787,7 +787,6 @@ * [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py) * [Shear Stress](physics/shear_stress.py) * [Speed Of Sound](physics/speed_of_sound.py) - * [Thermodynamics Work Done Formulae](physics/thermodynamics_work_done_formulae.py) ## Project Euler * Problem 001 From 2b75817a19e9d25577c7d65d81a5c0670b25456f Mon Sep 17 00:00:00 2001 From: Vipin Karthic <143083087+vipinkarthic@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:56:48 +0530 Subject: [PATCH 17/20] Rename binary_exponentiation_3.py to binary_exponentiation_2.py --- maths/{binary_exponentiation_3.py => binary_exponentiation_2.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename maths/{binary_exponentiation_3.py => binary_exponentiation_2.py} (100%) diff --git a/maths/binary_exponentiation_3.py b/maths/binary_exponentiation_2.py similarity index 100% rename from maths/binary_exponentiation_3.py rename to maths/binary_exponentiation_2.py From beb7395e035b35a7af64cda348d6d39986814734 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 9 Oct 2023 12:27:03 +0000 Subject: [PATCH 18/20] updating DIRECTORY.md --- DIRECTORY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index ffc83292c68d..d4659cee260c 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -560,7 +560,7 @@ * [Bell Numbers](maths/bell_numbers.py) * [Binary Exp Mod](maths/binary_exp_mod.py) * [Binary Exponentiation](maths/binary_exponentiation.py) - * [Binary Exponentiation 3](maths/binary_exponentiation_3.py) + * [Binary Exponentiation 2](maths/binary_exponentiation_2.py) * [Binary Multiplication](maths/binary_multiplication.py) * [Binomial Coefficient](maths/binomial_coefficient.py) * [Binomial Distribution](maths/binomial_distribution.py) From 36d56fdbe59beb5c2803b729400ff8ccacb0936a Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Tue, 10 Oct 2023 05:40:28 +0000 Subject: [PATCH 19/20] updating DIRECTORY.md --- DIRECTORY.md | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 31db03e6d62d..015efb3c796d 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -54,13 +54,12 @@ * [Largest Pow Of Two Le Num](bit_manipulation/largest_pow_of_two_le_num.py) * [Missing Number](bit_manipulation/missing_number.py) * [Numbers Different Signs](bit_manipulation/numbers_different_signs.py) + * [Power Of 4](bit_manipulation/power_of_4.py) * [Reverse Bits](bit_manipulation/reverse_bits.py) * [Single Bit Manipulation Operations](bit_manipulation/single_bit_manipulation_operations.py) ## Blockchain - * [Chinese Remainder Theorem](blockchain/chinese_remainder_theorem.py) * [Diophantine Equation](blockchain/diophantine_equation.py) - * [Modular Division](blockchain/modular_division.py) ## Boolean Algebra * [And Gate](boolean_algebra/and_gate.py) @@ -107,6 +106,7 @@ * [Mono Alphabetic Ciphers](ciphers/mono_alphabetic_ciphers.py) * [Morse Code](ciphers/morse_code.py) * [Onepad Cipher](ciphers/onepad_cipher.py) + * [Permutation Cipher](ciphers/permutation_cipher.py) * [Playfair Cipher](ciphers/playfair_cipher.py) * [Polybius](ciphers/polybius.py) * [Porta Cipher](ciphers/porta_cipher.py) @@ -173,6 +173,7 @@ ## Data Structures * Arrays + * [Equilibrium Index In Array](data_structures/arrays/equilibrium_index_in_array.py) * [Median Two Array](data_structures/arrays/median_two_array.py) * [Permutations](data_structures/arrays/permutations.py) * [Prefix Sum](data_structures/arrays/prefix_sum.py) @@ -469,6 +470,7 @@ * [Test Min Spanning Tree Prim](graphs/tests/test_min_spanning_tree_prim.py) ## Greedy Methods + * [Best Time To Buy And Sell Stock](greedy_methods/best_time_to_buy_and_sell_stock.py) * [Fractional Cover Problem](greedy_methods/fractional_cover_problem.py) * [Fractional Knapsack](greedy_methods/fractional_knapsack.py) * [Fractional Knapsack 2](greedy_methods/fractional_knapsack_2.py) @@ -528,6 +530,10 @@ * Local Weighted Learning * [Local Weighted Learning](machine_learning/local_weighted_learning/local_weighted_learning.py) * [Logistic Regression](machine_learning/logistic_regression.py) + * Loss Functions + * [Binary Cross Entropy](machine_learning/loss_functions/binary_cross_entropy.py) + * [Huber Loss](machine_learning/loss_functions/huber_loss.py) + * [Mean Squared Error](machine_learning/loss_functions/mean_squared_error.py) * [Mfcc](machine_learning/mfcc.py) * [Multilayer Perceptron Classifier](machine_learning/multilayer_perceptron_classifier.py) * [Polynomial Regression](machine_learning/polynomial_regression.py) @@ -568,7 +574,9 @@ * [Carmichael Number](maths/carmichael_number.py) * [Catalan Number](maths/catalan_number.py) * [Ceil](maths/ceil.py) + * [Chebyshev Distance](maths/chebyshev_distance.py) * [Check Polygon](maths/check_polygon.py) + * [Chinese Remainder Theorem](maths/chinese_remainder_theorem.py) * [Chudnovsky Algorithm](maths/chudnovsky_algorithm.py) * [Collatz Sequence](maths/collatz_sequence.py) * [Combinations](maths/combinations.py) @@ -595,6 +603,7 @@ * [Gaussian](maths/gaussian.py) * [Gaussian Error Linear Unit](maths/gaussian_error_linear_unit.py) * [Gcd Of N Numbers](maths/gcd_of_n_numbers.py) + * [Germain Primes](maths/germain_primes.py) * [Greatest Common Divisor](maths/greatest_common_divisor.py) * [Greedy Coin Change](maths/greedy_coin_change.py) * [Hamming Numbers](maths/hamming_numbers.py) @@ -622,7 +631,9 @@ * [Matrix Exponentiation](maths/matrix_exponentiation.py) * [Max Sum Sliding Window](maths/max_sum_sliding_window.py) * [Median Of Two Arrays](maths/median_of_two_arrays.py) + * [Minkowski Distance](maths/minkowski_distance.py) * [Mobius Function](maths/mobius_function.py) + * [Modular Division](maths/modular_division.py) * [Modular Exponential](maths/modular_exponential.py) * [Monte Carlo](maths/monte_carlo.py) * [Monte Carlo Dice](maths/monte_carlo_dice.py) @@ -724,13 +735,16 @@ ## Neural Network * [2 Hidden Layers Neural Network](neural_network/2_hidden_layers_neural_network.py) * Activation Functions + * [Binary Step](neural_network/activation_functions/binary_step.py) * [Exponential Linear Unit](neural_network/activation_functions/exponential_linear_unit.py) * [Leaky Rectified Linear Unit](neural_network/activation_functions/leaky_rectified_linear_unit.py) * [Mish](neural_network/activation_functions/mish.py) * [Rectified Linear Unit](neural_network/activation_functions/rectified_linear_unit.py) * [Scaled Exponential Linear Unit](neural_network/activation_functions/scaled_exponential_linear_unit.py) * [Sigmoid Linear Unit](neural_network/activation_functions/sigmoid_linear_unit.py) + * [Soboleva Modified Hyperbolic Tangent](neural_network/activation_functions/soboleva_modified_hyperbolic_tangent.py) * [Softplus](neural_network/activation_functions/softplus.py) + * [Squareplus](neural_network/activation_functions/squareplus.py) * [Back Propagation Neural Network](neural_network/back_propagation_neural_network.py) * [Convolution Neural Network](neural_network/convolution_neural_network.py) * [Perceptron](neural_network/perceptron.py) @@ -784,6 +798,7 @@ * [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py) * [Photoelectric Effect](physics/photoelectric_effect.py) * [Potential Energy](physics/potential_energy.py) + * [Reynolds Number](physics/reynolds_number.py) * [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py) * [Shear Stress](physics/shear_stress.py) * [Speed Of Sound](physics/speed_of_sound.py) @@ -1106,6 +1121,7 @@ * [Interpolation Search](searches/interpolation_search.py) * [Jump Search](searches/jump_search.py) * [Linear Search](searches/linear_search.py) + * [Median Of Medians](searches/median_of_medians.py) * [Quick Select](searches/quick_select.py) * [Sentinel Linear Search](searches/sentinel_linear_search.py) * [Simple Binary Search](searches/simple_binary_search.py) @@ -1206,6 +1222,7 @@ * [Snake Case To Camel Pascal Case](strings/snake_case_to_camel_pascal_case.py) * [Split](strings/split.py) * [String Switch Case](strings/string_switch_case.py) + * [Strip](strings/strip.py) * [Text Justification](strings/text_justification.py) * [Top K Frequent Words](strings/top_k_frequent_words.py) * [Upper](strings/upper.py) From 4287fd072d30031b171db20005fbe704fd29eead Mon Sep 17 00:00:00 2001 From: Tianyi Zheng Date: Tue, 10 Oct 2023 01:43:13 -0400 Subject: [PATCH 20/20] Formatting --- maths/binary_exponentiation_2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maths/binary_exponentiation_2.py b/maths/binary_exponentiation_2.py index 55fdf9ec80be..edb6b66b2594 100644 --- a/maths/binary_exponentiation_2.py +++ b/maths/binary_exponentiation_2.py @@ -25,7 +25,7 @@ def b_expo(a: int, b: int) -> int: 1 >>> b_expo(0, 12) 0 - >>> b_expo(4,12) + >>> b_expo(4, 12) 16777216 """ res = 1 @@ -43,11 +43,11 @@ def b_expo_mod(a: int, b: int, c: int) -> int: """ >>> b_expo_mod(2, 10, 1000000007) 1024 - >>> b_expo_mod(11,13,19) + >>> b_expo_mod(11, 13, 19) 11 >>> b_expo_mod(0, 19, 20) 0 - >>> b_expo_mod(15, 5 , 4) + >>> b_expo_mod(15, 5, 4) 3 """ res = 1