aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-289/eric-cheung/python')
-rwxr-xr-xchallenge-289/eric-cheung/python/ch-1.py13
-rwxr-xr-xchallenge-289/eric-cheung/python/ch-2.py17
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)