aboutsummaryrefslogtreecommitdiff
path: root/challenge-220/eric-cheung/python/ch-2.py
blob: 937099256459dd447e6be635f4ad683645438e7a (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
26
from itertools import permutations
from math import sqrt

def IsPerfectSqr (nInput):
    dSqRoot = int(sqrt(nInput))
    return (dSqRoot * dSqRoot == nInput)

arrIntList = [1, 17, 8]  ## Example 1
## arrIntList = [2, 2, 2]  ## Example 2

arrOutputList = []

arrPerm = set(permutations(arrIntList))

for permLoop in list(arrPerm):
    bIsSqrFul = True
    for nIndx in range(0, len(permLoop) - 1):
        if not IsPerfectSqr(permLoop[nIndx] + permLoop[nIndx + 1]):
            bIsSqrFul = False
            break

    if bIsSqrFul and not permLoop in arrOutputList:
        arrOutputList.append(permLoop)

print (arrOutputList)