blob: c75bd2bbb0888a0f16ff6123ab9b34ef6c86560a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/usr/bin/env python3
from itertools import combinations
def strong_pair(*integers):
""" Given an array of integers, return the count of all strong pairs in the
given array.
A pair of integers x and y is called strong pair if it satisfies:
0 < |x - y| < min(x, y).
>>> strong_pair(1, 2, 3, 4, 5)
4
>>> strong_pair(5, 7, 1, 7)
1
"""
return len({(x, y) for x, y in combinations(integers, 2)
if 0 < abs(x - y) and abs(x - y) < min(x, y)})
if __name__ == "__main__":
import doctest
doctest.testmod(verbose=True)
|