From d30952cafacb65e82ab58cfbfc438c796e7d02da Mon Sep 17 00:00:00 2001 From: happiestbee <87628038+happiestbee@users.noreply.github.com> Date: Thu, 6 Oct 2022 00:27:40 -0400 Subject: [PATCH 1/7] Create sumset.py --- maths/sumset.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 maths/sumset.py diff --git a/maths/sumset.py b/maths/sumset.py new file mode 100644 index 000000000000..2d89d0aad21b --- /dev/null +++ b/maths/sumset.py @@ -0,0 +1,36 @@ +""" + +Calculates the SumSet of two sets of numbers (A and B) + +Source: + https://en.wikipedia.org/wiki/Sumset + +""" + + +def sumset(A: set, B: set) -> set: + """ + :param first set: a set of numbers + :param second set: a set of numbers + :return: the nth number in Sylvester's sequence + + >>> sumset({1, 2, 3}, {4, 5, 6}) + {5, 6, 7, 8, 9} + + >>> sumset({1, 2, 3}, {4, 5, 6, 7}) + {5, 6, 7, 8, 9, 10} + + >>> sumset({1, 2, 3, 4}, 3) + Traceback (most recent call last): + ... + AssertionError: The input value of [B=3] is not a set + """ + assert isinstance(A, set), "The input value of [A={}] is not a set".format(A) + assert isinstance(B, set), "The input value of [B={}] is not a set".format(B) + + return {a + b for a in A for b in B} + +if __name__ == "__main__": + from doctest import testmod + + testmod() From 40298a1051f12e99b2301c7741a3e4503bb92244 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Thu, 6 Oct 2022 04:29:10 +0000 Subject: [PATCH 2/7] updating DIRECTORY.md --- DIRECTORY.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index 64e9d5333a2f..d7a7a071471e 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -574,6 +574,7 @@ * [Sum Of Arithmetic Series](maths/sum_of_arithmetic_series.py) * [Sum Of Digits](maths/sum_of_digits.py) * [Sum Of Geometric Progression](maths/sum_of_geometric_progression.py) + * [Sumset](maths/sumset.py) * [Sylvester Sequence](maths/sylvester_sequence.py) * [Test Prime Check](maths/test_prime_check.py) * [Trapezoidal Rule](maths/trapezoidal_rule.py) @@ -632,7 +633,7 @@ ## Physics * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py) - * [Lorenz Transformation Four Vector](physics/lorenz_transformation_four_vector.py) + * [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py) * [N Body Simulation](physics/n_body_simulation.py) * [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py) From f1c2b19e4cd110bc0c77e3a14cfadc4ee5ae19eb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 6 Oct 2022 04:30:39 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/sumset.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/maths/sumset.py b/maths/sumset.py index 2d89d0aad21b..2b51c730d7c1 100644 --- a/maths/sumset.py +++ b/maths/sumset.py @@ -10,26 +10,27 @@ def sumset(A: set, B: set) -> set: """ - :param first set: a set of numbers + :param first set: a set of numbers :param second set: a set of numbers :return: the nth number in Sylvester's sequence - + >>> sumset({1, 2, 3}, {4, 5, 6}) {5, 6, 7, 8, 9} - + >>> sumset({1, 2, 3}, {4, 5, 6, 7}) {5, 6, 7, 8, 9, 10} - + >>> sumset({1, 2, 3, 4}, 3) Traceback (most recent call last): ... AssertionError: The input value of [B=3] is not a set """ - assert isinstance(A, set), "The input value of [A={}] is not a set".format(A) - assert isinstance(B, set), "The input value of [B={}] is not a set".format(B) - + assert isinstance(A, set), f"The input value of [A={A}] is not a set" + assert isinstance(B, set), f"The input value of [B={B}] is not a set" + return {a + b for a in A for b in B} + if __name__ == "__main__": from doctest import testmod From 7de1262ba554d345931962ff46dcbf683b71bd18 Mon Sep 17 00:00:00 2001 From: happiestbee <87628038+happiestbee@users.noreply.github.com> Date: Thu, 6 Oct 2022 07:55:53 -0400 Subject: [PATCH 4/7] Add descriptive var names --- maths/sumset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/sumset.py b/maths/sumset.py index 2b51c730d7c1..7d751e99818e 100644 --- a/maths/sumset.py +++ b/maths/sumset.py @@ -8,7 +8,7 @@ """ -def sumset(A: set, B: set) -> set: +def sumset(set_a: set, set_b: set) -> set: """ :param first set: a set of numbers :param second set: a set of numbers @@ -25,10 +25,10 @@ def sumset(A: set, B: set) -> set: ... AssertionError: The input value of [B=3] is not a set """ - assert isinstance(A, set), f"The input value of [A={A}] is not a set" - assert isinstance(B, set), f"The input value of [B={B}] is not a set" + assert isinstance(set_a, set), f"The input value of [set_a={set_a}] is not a set" + assert isinstance(set_b, set), f"The input value of [B={set_b}] is not a set" - return {a + b for a in A for b in B} + return {a + b for a in set_a for b in set_b} if __name__ == "__main__": From 2a30ae723445535a552841b1e10dad5a5796a798 Mon Sep 17 00:00:00 2001 From: happiestbee <87628038+happiestbee@users.noreply.github.com> Date: Thu, 6 Oct 2022 11:37:38 -0400 Subject: [PATCH 5/7] Update maths/sumset.py Co-authored-by: Caeden --- maths/sumset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sumset.py b/maths/sumset.py index 7d751e99818e..d17ffee50999 100644 --- a/maths/sumset.py +++ b/maths/sumset.py @@ -26,7 +26,7 @@ def sumset(set_a: set, set_b: set) -> set: AssertionError: The input value of [B=3] is not a set """ assert isinstance(set_a, set), f"The input value of [set_a={set_a}] is not a set" - assert isinstance(set_b, set), f"The input value of [B={set_b}] is not a set" + assert isinstance(set_b, set), f"The input value of [set_b={set_b}] is not a set" return {a + b for a in set_a for b in set_b} From 4de4991103d8bac6b84151f8154260bf509e27c3 Mon Sep 17 00:00:00 2001 From: happiestbee <87628038+happiestbee@users.noreply.github.com> Date: Thu, 6 Oct 2022 12:19:02 -0400 Subject: [PATCH 6/7] Update sumset.py --- maths/sumset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/sumset.py b/maths/sumset.py index d17ffee50999..fa18f9e24b4c 100644 --- a/maths/sumset.py +++ b/maths/sumset.py @@ -23,7 +23,7 @@ def sumset(set_a: set, set_b: set) -> set: >>> sumset({1, 2, 3, 4}, 3) Traceback (most recent call last): ... - AssertionError: The input value of [B=3] is not a set + AssertionError: The input value of [set_b=3] is not a set """ assert isinstance(set_a, set), f"The input value of [set_a={set_a}] is not a set" assert isinstance(set_b, set), f"The input value of [set_b={set_b}] is not a set" From a40cc7fcfe3f752ae9354875323818aa8b7678b8 Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Sun, 30 Oct 2022 10:46:49 +0000 Subject: [PATCH 7/7] updating DIRECTORY.md --- DIRECTORY.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/DIRECTORY.md b/DIRECTORY.md index fc0c6de6e980..38fd1d656488 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -560,6 +560,7 @@ * [Lucas Lehmer Primality Test](maths/lucas_lehmer_primality_test.py) * [Lucas Series](maths/lucas_series.py) * [Maclaurin Series](maths/maclaurin_series.py) + * [Manhattan Distance](maths/manhattan_distance.py) * [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) @@ -615,8 +616,8 @@ * [Sum Of Arithmetic Series](maths/sum_of_arithmetic_series.py) * [Sum Of Digits](maths/sum_of_digits.py) * [Sum Of Geometric Progression](maths/sum_of_geometric_progression.py) - * [Sumset](maths/sumset.py) * [Sum Of Harmonic Series](maths/sum_of_harmonic_series.py) + * [Sumset](maths/sumset.py) * [Sylvester Sequence](maths/sylvester_sequence.py) * [Test Prime Check](maths/test_prime_check.py) * [Trapezoidal Rule](maths/trapezoidal_rule.py) @@ -684,6 +685,7 @@ * [Casimir Effect](physics/casimir_effect.py) * [Centripetal Force](physics/centripetal_force.py) * [Horizontal Projectile Motion](physics/horizontal_projectile_motion.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) * [Malus Law](physics/malus_law.py) @@ -691,6 +693,7 @@ * [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py) * [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py) * [Potential Energy](physics/potential_energy.py) + * [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py) * [Sheer Stress](physics/sheer_stress.py) ## Project Euler @@ -979,6 +982,7 @@ * [Not Gate](quantum/not_gate.py) * [Q Full Adder](quantum/q_full_adder.py) * [Quantum Entanglement](quantum/quantum_entanglement.py) + * [Quantum Teleportation](quantum/quantum_teleportation.py) * [Ripple Adder Classic](quantum/ripple_adder_classic.py) * [Single Qubit Measure](quantum/single_qubit_measure.py) * [Superdense Coding](quantum/superdense_coding.py)