diff options
Diffstat (limited to 'challenge-220/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-220/eric-cheung/python/ch-2.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/challenge-220/eric-cheung/python/ch-2.py b/challenge-220/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..9370992564 --- /dev/null +++ b/challenge-220/eric-cheung/python/ch-2.py @@ -0,0 +1,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)
|
