aboutsummaryrefslogtreecommitdiff
path: root/challenge-327/eric-cheung/python/ch-2.py
blob: 4f5c71f173cb5900bd9dde16a88234bfef463947 (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
from itertools import combinations

## arrInts = [4, 1, 2, 3]  ## Example 1
## arrInts = [1, 3, 7, 11, 15]  ## Example 2
arrInts = [1, 5, 3, 8]  ## Example 3

arrCombList = combinations(arrInts, 2)

arrOutput = []
nMinAbsDiff = max(arrInts) - min(arrInts)

for arrLoop in arrCombList:
    nAbsDiff = abs(arrLoop[0] - arrLoop[1])

    if nAbsDiff > nMinAbsDiff:
        continue

    if nAbsDiff < nMinAbsDiff:
        nMinAbsDiff = nAbsDiff
        arrOutput = []

    arrOutput.append(sorted(list(arrLoop)))

print (sorted(arrOutput))