@@ -0,0 +1,673 @@
+def has_swap(A, B):%0A    %22Is there one exchange between A and B that'll make their sums equal?%22%0A    # https://codility.com/media/train/2-CountingElements.pdf%0A    # assert len(A) == len(B)%0A    # assert all(type(a) == int for a in A)%0A    # assert all(type(b) == int for b in B)%0A%0A    sum_A = sum(A)%0A    sum_B = sum(B)%0A    diff = sum_A - sum_B%0A%0A    if diff %25 2 == 1:%0A        return False%0A%0A    set_A = set(A)%0A    # The exchange should change sum(A) by -(diff / 2)%0A    # So the exchange should be: B%5Bj%5D - A%5Bi%5D = -(diff / 2),%0A    # making the complement of B%5Bj%5D be A%5Bi%5D = B%5Bj%5D + diff / 2.%0A    complement = lambda b: b + diff / 2%0A    return any((complement(b) in set_A) for b in B)%0A

Create has_swap.py