Exemplo n.º 1
0
    def test_union(self):
        """
        Checks for union().
        """
        set1 = Multiset({"a": 10, "b": 20})
        set2 = Multiset({"a": 1, "c": 2})
        set3 = Multiset({"a": 11, "b": 20, "c": 2})
        self.assertEqual(set1.union(set2), set3)

        set1 = Multiset({"a": 10, "b": 20})
        set2 = Multiset({"x": 1, "y": 2})
        set3 = Multiset({"a": 10, "b": 20, "x": 1, "y": 2})
        self.assertEqual(set1.union(set2), set3)
Exemplo n.º 2
0
def LCM(x, y):
    pfx = Multiset(primefactors(x))
    pfy = Multiset(primefactors(y))
    gcf = 1
    union = pfx.union(pfy)
    for p in union:
        gcf = gcf * p
    return gcf
Exemplo n.º 3
0
def p5(n: int):
    # What is the smallest positive number
    # that is evenly divisible
    # by all of the numbers from 1 to n ?

    P = Prime()
    divisors = list(map(P.factorize, range(2, n)))

    x = Multiset()
    for _ in divisors:
        x = x.union(_)

    x = np.prod(x)
    print(x)
    return x
Exemplo n.º 4
0
def jaccard_index(a: multiset.Multiset, b: multiset.Multiset) -> float:
    num = len(a.intersection(b))
    den = len(a.union(b))
    return num / den if den else np.nan