diff options
| author | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-01-22 18:45:40 +0000 |
|---|---|---|
| committer | Mohammad S Anwar <mohammad.anwar@yahoo.com> | 2024-01-22 18:45:40 +0000 |
| commit | 8db85cd488ebedbbda40cca5403676ce0ed8e072 (patch) | |
| tree | d33d82158a36712744dfe056a614af5efd7d392d /challenge-253/eric-cheung/python | |
| parent | e5950fec13757372c56fd4a6fe34acb64e03f261 (diff) | |
| download | perlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.tar.gz perlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.tar.bz2 perlweeklychallenge-club-8db85cd488ebedbbda40cca5403676ce0ed8e072.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Laurent Rosenfeld.
- Added solutions by Mark Anderson.
- Added solutions by Niels van Dijke.
- Added solutions by PokGoPun.
- Added solutions by Luca Ferrari.
- Added solutions by David Ferrone.
- Added solutions by W. Luis Mochan.
Diffstat (limited to 'challenge-253/eric-cheung/python')
| -rwxr-xr-x | challenge-253/eric-cheung/python/ch-1.py | 14 | ||||
| -rwxr-xr-x | challenge-253/eric-cheung/python/ch-2.py | 17 |
2 files changed, 31 insertions, 0 deletions
diff --git a/challenge-253/eric-cheung/python/ch-1.py b/challenge-253/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..ac1c18f9c5 --- /dev/null +++ b/challenge-253/eric-cheung/python/ch-1.py @@ -0,0 +1,14 @@ +
+## Example 1
+arrWords = ["one.two.three", "four.five", "six"]
+strSeparator = "."
+
+## Example 2
+## arrWords = ["$perl$$", "$$raku$"]
+## strSeparator = "$"
+
+arrOutput = []
+for strLoop in arrWords:
+ arrOutput = arrOutput + strLoop.split(strSeparator)
+
+print (",".join(["\"" + strLoop + "\"" for strLoop in arrOutput if strLoop]))
diff --git a/challenge-253/eric-cheung/python/ch-2.py b/challenge-253/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..91e11aaa8b --- /dev/null +++ b/challenge-253/eric-cheung/python/ch-2.py @@ -0,0 +1,17 @@ +
+def IsWeaker (rowA, rowB):
+ return True if rowA.count(1) <= rowB.count(1) else False
+
+## arrMatrix = [[1, 1, 0, 0, 0], [1, 1, 1, 1, 0], [1, 0, 0, 0, 0], [1, 1, 0, 0, 0], [1, 1, 1, 1, 1]] ## Example 1
+arrMatrix = [[1, 0, 0, 0], [1, 1, 1, 1], [1, 0, 0, 0], [1, 0, 0, 0]] ## Example 2
+
+arrIndx = [nIndx for nIndx in range(len(arrMatrix))]
+
+for nRowLoop in range(len(arrIndx) - 1):
+ for nColLoop in range(nRowLoop + 1, len(arrIndx)):
+ if not IsWeaker (arrMatrix[arrIndx[nRowLoop]], arrMatrix[arrIndx[nColLoop]]):
+ vTemp = arrIndx[nRowLoop]
+ arrIndx[nRowLoop] = arrIndx[nColLoop]
+ arrIndx[nColLoop] = vTemp
+
+print (arrIndx)
|
