mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
added sumset.py Fixes: #{6563} (#6742)
* Create sumset.py * updating DIRECTORY.md * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add descriptive var names * Update maths/sumset.py Co-authored-by: Caeden <caedenperelliharris@gmail.com> * Update sumset.py * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Caeden <caedenperelliharris@gmail.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
parent
fcfe35c3d8
commit
00fc53de97
|
@ -560,6 +560,7 @@
|
||||||
* [Lucas Lehmer Primality Test](maths/lucas_lehmer_primality_test.py)
|
* [Lucas Lehmer Primality Test](maths/lucas_lehmer_primality_test.py)
|
||||||
* [Lucas Series](maths/lucas_series.py)
|
* [Lucas Series](maths/lucas_series.py)
|
||||||
* [Maclaurin Series](maths/maclaurin_series.py)
|
* [Maclaurin Series](maths/maclaurin_series.py)
|
||||||
|
* [Manhattan Distance](maths/manhattan_distance.py)
|
||||||
* [Matrix Exponentiation](maths/matrix_exponentiation.py)
|
* [Matrix Exponentiation](maths/matrix_exponentiation.py)
|
||||||
* [Max Sum Sliding Window](maths/max_sum_sliding_window.py)
|
* [Max Sum Sliding Window](maths/max_sum_sliding_window.py)
|
||||||
* [Median Of Two Arrays](maths/median_of_two_arrays.py)
|
* [Median Of Two Arrays](maths/median_of_two_arrays.py)
|
||||||
|
@ -616,6 +617,7 @@
|
||||||
* [Sum Of Digits](maths/sum_of_digits.py)
|
* [Sum Of Digits](maths/sum_of_digits.py)
|
||||||
* [Sum Of Geometric Progression](maths/sum_of_geometric_progression.py)
|
* [Sum Of Geometric Progression](maths/sum_of_geometric_progression.py)
|
||||||
* [Sum Of Harmonic Series](maths/sum_of_harmonic_series.py)
|
* [Sum Of Harmonic Series](maths/sum_of_harmonic_series.py)
|
||||||
|
* [Sumset](maths/sumset.py)
|
||||||
* [Sylvester Sequence](maths/sylvester_sequence.py)
|
* [Sylvester Sequence](maths/sylvester_sequence.py)
|
||||||
* [Test Prime Check](maths/test_prime_check.py)
|
* [Test Prime Check](maths/test_prime_check.py)
|
||||||
* [Trapezoidal Rule](maths/trapezoidal_rule.py)
|
* [Trapezoidal Rule](maths/trapezoidal_rule.py)
|
||||||
|
@ -683,6 +685,7 @@
|
||||||
* [Casimir Effect](physics/casimir_effect.py)
|
* [Casimir Effect](physics/casimir_effect.py)
|
||||||
* [Centripetal Force](physics/centripetal_force.py)
|
* [Centripetal Force](physics/centripetal_force.py)
|
||||||
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
|
* [Horizontal Projectile Motion](physics/horizontal_projectile_motion.py)
|
||||||
|
* [Ideal Gas Law](physics/ideal_gas_law.py)
|
||||||
* [Kinetic Energy](physics/kinetic_energy.py)
|
* [Kinetic Energy](physics/kinetic_energy.py)
|
||||||
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
|
* [Lorentz Transformation Four Vector](physics/lorentz_transformation_four_vector.py)
|
||||||
* [Malus Law](physics/malus_law.py)
|
* [Malus Law](physics/malus_law.py)
|
||||||
|
@ -690,6 +693,7 @@
|
||||||
* [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py)
|
* [Newtons Law Of Gravitation](physics/newtons_law_of_gravitation.py)
|
||||||
* [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py)
|
* [Newtons Second Law Of Motion](physics/newtons_second_law_of_motion.py)
|
||||||
* [Potential Energy](physics/potential_energy.py)
|
* [Potential Energy](physics/potential_energy.py)
|
||||||
|
* [Rms Speed Of Molecule](physics/rms_speed_of_molecule.py)
|
||||||
* [Sheer Stress](physics/sheer_stress.py)
|
* [Sheer Stress](physics/sheer_stress.py)
|
||||||
|
|
||||||
## Project Euler
|
## Project Euler
|
||||||
|
@ -978,6 +982,7 @@
|
||||||
* [Not Gate](quantum/not_gate.py)
|
* [Not Gate](quantum/not_gate.py)
|
||||||
* [Q Full Adder](quantum/q_full_adder.py)
|
* [Q Full Adder](quantum/q_full_adder.py)
|
||||||
* [Quantum Entanglement](quantum/quantum_entanglement.py)
|
* [Quantum Entanglement](quantum/quantum_entanglement.py)
|
||||||
|
* [Quantum Teleportation](quantum/quantum_teleportation.py)
|
||||||
* [Ripple Adder Classic](quantum/ripple_adder_classic.py)
|
* [Ripple Adder Classic](quantum/ripple_adder_classic.py)
|
||||||
* [Single Qubit Measure](quantum/single_qubit_measure.py)
|
* [Single Qubit Measure](quantum/single_qubit_measure.py)
|
||||||
* [Superdense Coding](quantum/superdense_coding.py)
|
* [Superdense Coding](quantum/superdense_coding.py)
|
||||||
|
|
37
maths/sumset.py
Normal file
37
maths/sumset.py
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
"""
|
||||||
|
|
||||||
|
Calculates the SumSet of two sets of numbers (A and B)
|
||||||
|
|
||||||
|
Source:
|
||||||
|
https://en.wikipedia.org/wiki/Sumset
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def sumset(set_a: set, 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 [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"
|
||||||
|
|
||||||
|
return {a + b for a in set_a for b in set_b}
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
from doctest import testmod
|
||||||
|
|
||||||
|
testmod()
|
Loading…
Reference in New Issue
Block a user