aboutsummaryrefslogtreecommitdiff
path: root/challenge-271/eric-cheung
diff options
context:
space:
mode:
authorMohammad S Anwar <mohammad.anwar@yahoo.com>2024-05-27 12:30:09 +0100
committerMohammad S Anwar <mohammad.anwar@yahoo.com>2024-05-27 12:30:09 +0100
commit121b188ff9875f14ddd1567ad62ceb734d1ed226 (patch)
treec17558bc57c5f1509a29016c8a94c841452292a4 /challenge-271/eric-cheung
parent72abeccd330b38f170d2f8b46692408519f27289 (diff)
downloadperlweeklychallenge-club-121b188ff9875f14ddd1567ad62ceb734d1ed226.tar.gz
perlweeklychallenge-club-121b188ff9875f14ddd1567ad62ceb734d1ed226.tar.bz2
perlweeklychallenge-club-121b188ff9875f14ddd1567ad62ceb734d1ed226.zip
- Added solutions by Eric Cheung.
- Added solutions by Bob Lied. - Added solutions by David Ferrone. - Added solutions by Packy Anderson. - Added solutions by PokGoPun. - Added solutions by Niels van Dijke. - Added solutions by Feng Chang. - Added solutions by Mark Anderson. - Added solutions by E. Choroba. - Added solutions by Steven Wilson.
Diffstat (limited to 'challenge-271/eric-cheung')
-rwxr-xr-xchallenge-271/eric-cheung/python/ch-1.py10
-rwxr-xr-xchallenge-271/eric-cheung/python/ch-2.py9
2 files changed, 19 insertions, 0 deletions
diff --git a/challenge-271/eric-cheung/python/ch-1.py b/challenge-271/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..4913afcb8a
--- /dev/null
+++ b/challenge-271/eric-cheung/python/ch-1.py
@@ -0,0 +1,10 @@
+
+import numpy as np
+
+## arrMatrix = [[0, 1], [1, 0]] ## Example 1
+## arrMatrix = [[0, 0, 0], [1, 0, 1]] ## Example 2
+arrMatrix = [[0, 0], [1, 1], [0, 0]] ## Example 3
+
+arrNumOne = [arrMatrix[nLoop].count(1) for nLoop in range(len(arrMatrix))]
+
+print (np.argmax(arrNumOne) + 1)
diff --git a/challenge-271/eric-cheung/python/ch-2.py b/challenge-271/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..847b810677
--- /dev/null
+++ b/challenge-271/eric-cheung/python/ch-2.py
@@ -0,0 +1,9 @@
+
+## arrInt = [0, 1, 2, 3, 4, 5, 6, 7, 8] ## Example 1
+arrInt = [1024, 512, 256, 128, 64] ## Example 2
+
+arrOrder = [[bin(nElem).replace("0b", "").count("1"), nElem] for nElem in arrInt]
+
+arrOutput = [nElem for strSort, nElem in sorted(arrOrder, key = lambda nElem: (nElem[0], nElem[1]))]
+
+print (arrOutput)