diff options
Diffstat (limited to 'challenge-244/eric-cheung/python/ch-2.py')
| -rwxr-xr-x | challenge-244/eric-cheung/python/ch-2.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-244/eric-cheung/python/ch-2.py b/challenge-244/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..637dcacca2 --- /dev/null +++ b/challenge-244/eric-cheung/python/ch-2.py @@ -0,0 +1,19 @@ +
+## Ref.
+## https://stackoverflow.com/questions/1482308/how-to-get-all-subsets-of-a-set-powerset
+
+from itertools import chain, combinations
+
+def GetPowerSet(arrInput):
+ return list(chain.from_iterable(combinations(arrInput, rLoop) for rLoop in range(1, len(arrInput) + 1)))
+
+arrNum = [2, 1, 4] ## Example 1
+
+nSum = 0
+
+for arrLoop in GetPowerSet(arrNum):
+ nMax = max(arrLoop)
+ nMin = min(arrLoop)
+ nSum = nSum + nMax * nMax * nMin
+
+print (nSum)
|
