diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-11-21 10:59:23 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2023-11-21 10:59:23 +0000 |
| commit | 1fba61b1b3b2804a16ab2f4052a8b67a01490dcf (patch) | |
| tree | 5609f39125c2a9f8597e7c07d3869a3a83143473 /challenge-244/eric-cheung/python | |
| parent | f274932c2e3b1f3fdc50013fa194a9ef2e2bf607 (diff) | |
| download | perlweeklychallenge-club-1fba61b1b3b2804a16ab2f4052a8b67a01490dcf.tar.gz perlweeklychallenge-club-1fba61b1b3b2804a16ab2f4052a8b67a01490dcf.tar.bz2 perlweeklychallenge-club-1fba61b1b3b2804a16ab2f4052a8b67a01490dcf.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Laurent Rosenfeld.
- Added solutions by Ulrich Rieke.
- Added solutions by E. Choroba.
- Added solutions by Luca Ferrari.
- Added solutions by Niels van Dijke.
- Added solutions by W. Luis Mochan.
- Added solutions by David Ferrone.
- Added solutions by Peter Meszaros.
- Added solutions by Steven Wilson.
- Added solutions by Thomas Kohler.
- Added solutions by Adam Russell.
- Added solutions by Humbeto Massa.
- Added solutions by Mark Anderson.
- Added solutions by Dave Jacoby.
- Added solutions by PokGoPun.
- Added solutions by Matthew Neleigh.
Diffstat (limited to 'challenge-244/eric-cheung/python')
| -rwxr-xr-x | challenge-244/eric-cheung/python/ch-1.py | 8 | ||||
| -rwxr-xr-x | challenge-244/eric-cheung/python/ch-2.py | 19 |
2 files changed, 27 insertions, 0 deletions
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)
|
