From fb4ae25cbf52df4ae59b5b7dfbd32004b67be604 Mon Sep 17 00:00:00 2001 From: Mohammad Sajid Anwar Date: Mon, 30 Sep 2024 15:28:46 +0100 Subject: - 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. --- challenge-289/eric-cheung/python/ch-1.py | 13 +++++++++++++ challenge-289/eric-cheung/python/ch-2.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 challenge-289/eric-cheung/python/ch-1.py create mode 100755 challenge-289/eric-cheung/python/ch-2.py (limited to 'challenge-289/eric-cheung/python') 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) -- cgit