def test_swap_two_existing_items(self) -> None:
     for (ai, a), (bi, b) in combinations_w_r(enumerate(self.items), 2):
         with self.subTest(a=a, b=b):
             ordering = Ordering[int](self.items)
             ordering.swap(a, b)
             items_copy = list(self.items)
             items_copy[ai], items_copy[bi] = items_copy[bi], items_copy[ai]
             self.assertListEqual(list(ordering), items_copy)
Esempio n. 2
0
 def _combinations(n_features, degree, include_interaction,
                   interaction_only, include_bias):
     comb = combinations if interaction_only else combinations_w_r
     start = int(not include_bias)
     if not include_interaction:
         if include_bias:
             return chain(
                 [()],
                 chain.from_iterable(
                     combinations_w_r([j], i) for i in range(1, degree + 1)
                     for j in range(n_features)),
             )
         else:
             return chain.from_iterable(
                 combinations_w_r([j], i) for i in range(1, degree + 1)
                 for j in range(n_features))
     return chain.from_iterable(
         comb(range(n_features), i) for i in range(start, degree + 1))
Esempio n. 3
0
 def _combinations(self, n_features, degree, include_bias):
     start = int(not include_bias)
     return chain.from_iterable(combinations_w_r(range(n_features), i)
                                for i in range(start, degree + 1))
Esempio n. 4
0
T = int(input())
for t in range(1, T + 1):
    N = int(input())
    equations = {}
    original_equations = {}
    for n in range(N):
        expression, z = input().split('=')
        x, y = expression.split('+')
        if (x, y) not in equations:
            z = int(z)
            equations[(x, y)] = equations[(y, x)] = z
            original_equations[(x, y)] = z
    previous_length = -1
    while len(equations) != previous_length:
        previous_length = len(equations)
        combinations = combinations_w_r(original_equations.items(), 2)
        for ((x1, y1), z1), ((x2, y2), z2) in combinations:
            if (x1, x2) in equations and (y1, y2) not in equations:
                z = z1 + z2 - equations[(x1, x2)]
                equations[(y1, y2)] = equations[(y2, y1)] = z
            if (x1, y2) in equations and (y1, x2) not in equations:
                z = z1 + z2 - equations[(x1, y2)]
                equations[(y1, x2)] = equations[(x2, y1)] = z
            if (y1, x2) in equations and (x1, y2) not in equations:
                z = z1 + z2 - equations[(y1, x2)]
                equations[(x1, y2)] = equations[(y2, x1)] = z
            if (y1, y2) in equations and (x1, x2) not in equations:
                z = z1 + z2 - equations[(y1, y2)]
                equations[(x1, x2)] = equations[(x2, x1)] = z
    print(f"Case #{t}:")
    Q = int(input())