aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/eric-cheung/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-331/eric-cheung/python')
-rwxr-xr-xchallenge-331/eric-cheung/python/ch-1.py12
-rwxr-xr-xchallenge-331/eric-cheung/python/ch-2.py32
2 files changed, 44 insertions, 0 deletions
diff --git a/challenge-331/eric-cheung/python/ch-1.py b/challenge-331/eric-cheung/python/ch-1.py
new file mode 100755
index 0000000000..a7d0dcd351
--- /dev/null
+++ b/challenge-331/eric-cheung/python/ch-1.py
@@ -0,0 +1,12 @@
+
+import re
+
+## strInput = "The Weekly Challenge" ## Example 1
+## strInput = " Hello World " ## Example 2
+strInput = "Let's begin the fun" ## Example 3
+
+strOutput = re.sub(r"\s+", " ", strInput).strip()
+
+arrOutput = [strLoop for strLoop in strOutput.split(" ") if strLoop]
+
+print (len(arrOutput[-1]))
diff --git a/challenge-331/eric-cheung/python/ch-2.py b/challenge-331/eric-cheung/python/ch-2.py
new file mode 100755
index 0000000000..3b21723f44
--- /dev/null
+++ b/challenge-331/eric-cheung/python/ch-2.py
@@ -0,0 +1,32 @@
+
+def IsBuddyStr (strSource, strTarget):
+ arrSource = list(strSource)
+
+ for nRow in range(0, len(arrSource) - 1):
+ for nCol in range(nRow + 1, len(arrSource)):
+ arrTemp = arrSource[:]
+ arrTemp[nRow] = arrSource[nCol]
+ arrTemp[nCol] = arrSource[nRow]
+ strSwap = "".join(arrTemp)
+ if strSwap == strTarget:
+ return True
+
+ return False
+
+## Example 1
+## strInputSource = "fuck"
+## strInputTarget = "fcuk"
+
+## Example 2
+## strInputSource = "love"
+## strInputTarget = "love"
+
+## Example 3
+## strInputSource = "fodo"
+## strInputTarget = "food"
+
+## Example 4
+strInputSource = "feed"
+strInputTarget = "feed"
+
+print (IsBuddyStr(strInputSource, strInputTarget))