diff options
| author | Lakpa Tashi Bhutia <lakpatashi@users.noreply.github.com> | 2023-11-25 21:02:55 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-11-25 21:02:55 +0530 |
| commit | 6db863c3ee8cb8a3315eeae5fde99af83385aefc (patch) | |
| tree | 761f0c9b8aef13375cca819d8deed4a70fff8c7e /challenge-244/eric-cheung | |
| parent | 9c96baeeda85997b321a4d4fbebd5fd51bffb729 (diff) | |
| parent | 9a1dd9390973363a40ccda4a6d03f9f61a0ae386 (diff) | |
| download | perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.tar.gz perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.tar.bz2 perlweeklychallenge-club-6db863c3ee8cb8a3315eeae5fde99af83385aefc.zip | |
Merge branch 'manwar:master' into master
Diffstat (limited to 'challenge-244/eric-cheung')
| -rw-r--r-- | challenge-244/eric-cheung/README | 1 | ||||
| -rwxr-xr-x | challenge-244/eric-cheung/python/ch-1.py | 8 | ||||
| -rwxr-xr-x | challenge-244/eric-cheung/python/ch-2.py | 19 |
3 files changed, 28 insertions, 0 deletions
diff --git a/challenge-244/eric-cheung/README b/challenge-244/eric-cheung/README new file mode 100644 index 0000000000..1bf6db4498 --- /dev/null +++ b/challenge-244/eric-cheung/README @@ -0,0 +1 @@ +Solutions by Eric Cheung. diff --git a/challenge-244/eric-cheung/python/ch-1.py b/challenge-244/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..0689b32341 --- /dev/null +++ b/challenge-244/eric-cheung/python/ch-1.py @@ -0,0 +1,8 @@ +
+## arrNum = [8, 1, 2, 2, 3] ## Example 1
+## arrNum = [6, 5, 4, 8] ## Example 2
+arrNum = [2, 2, 2] ## Example 3
+
+arrOutput = [sum(nLoop < nNumLoop for nLoop in arrNum) for nNumLoop in arrNum]
+
+print (arrOutput)
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)
|
