diff options
| author | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-30 15:28:46 +0100 |
|---|---|---|
| committer | Mohammad Sajid Anwar <mohammad.anwar@yahoo.com> | 2024-09-30 15:28:46 +0100 |
| commit | fb4ae25cbf52df4ae59b5b7dfbd32004b67be604 (patch) | |
| tree | d4a20000e9c992ac58f2081ef4389db1d026c061 /challenge-289/eric-cheung/python | |
| parent | 178d4e45aa6ff1bcc926830d279bdd1f54a0eaac (diff) | |
| download | perlweeklychallenge-club-fb4ae25cbf52df4ae59b5b7dfbd32004b67be604.tar.gz perlweeklychallenge-club-fb4ae25cbf52df4ae59b5b7dfbd32004b67be604.tar.bz2 perlweeklychallenge-club-fb4ae25cbf52df4ae59b5b7dfbd32004b67be604.zip | |
- Added solutions by Eric Cheung.
- Added solutions by Jan Krnavek.
- Added solutions by W. Luis Mochan.
- Added solutions by Lubos Kolouch.
- Added solutions by Robbie Hatley.
- Added solutions by Paulo Custodio.
- Added solutions by Niels van Dijke.
- Added solutions by Conor Hoekstra.
- Added solutions by Bob Lied.
- Added solutions by Luca Ferrari.
Diffstat (limited to 'challenge-289/eric-cheung/python')
| -rwxr-xr-x | challenge-289/eric-cheung/python/ch-1.py | 13 | ||||
| -rwxr-xr-x | challenge-289/eric-cheung/python/ch-2.py | 17 |
2 files changed, 30 insertions, 0 deletions
diff --git a/challenge-289/eric-cheung/python/ch-1.py b/challenge-289/eric-cheung/python/ch-1.py new file mode 100755 index 0000000000..c54d1cff0a --- /dev/null +++ b/challenge-289/eric-cheung/python/ch-1.py @@ -0,0 +1,13 @@ +
+## arrInt = [5, 6, 4, 1] ## Example 1
+## arrInt = [4, 5] ## Example 2
+arrInt = [1, 2, 2, 3] ## Example 3
+
+arrOutput = sorted(set(arrInt), reverse = True)
+
+## print (arrOutput)
+
+if len(arrOutput) >= 3:
+ print (arrOutput[2])
+else:
+ print (arrOutput[0])
\ No newline at end of file diff --git a/challenge-289/eric-cheung/python/ch-2.py b/challenge-289/eric-cheung/python/ch-2.py new file mode 100755 index 0000000000..09f789c2a5 --- /dev/null +++ b/challenge-289/eric-cheung/python/ch-2.py @@ -0,0 +1,17 @@ +
+import random
+
+def GetWordShuffle (strInput):
+ arrChar = [nIndx for nIndx, charLoop in enumerate(strInput) if charLoop.isalpha()]
+
+ arrSubChar = [nIndx for nIndx in arrChar[1:-1]]
+ random.shuffle(arrSubChar)
+
+ return strInput[:arrChar[0] + 1] + "".join([strInput[nIndx] for nIndx in arrSubChar]) + strInput[arrChar[-1]]
+
+## strInput = "Perl" ## Example 1
+strInput = "According to a researcher (sic) at Cambridge University, it doesn't matter in what order the letters in a word are, the only important thing is that the first and last letter be at the right place. The rest can be a total mess and you can still read it without problem. This is because the human mind does not read every letter by itself but the word as a whole." ## Example 2
+
+strOutput = " ".join([GetWordShuffle(strLoop) for strLoop in strInput.split(" ")])
+
+print (strOutput)
|
