aboutsummaryrefslogtreecommitdiff
path: root/challenge-331/eric-cheung/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-07-22 00:44:04 +0100
committerMohammad Sajid Anwar <mohammad.anwar@yahoo.com>2025-07-22 00:44:04 +0100
commitc5ca130343e62834e6079e43b5cb9588ce0243b1 (patch)
tree181a67d80a7c27d84101f21a9fe2f58435475344 /challenge-331/eric-cheung/python
parent1131559ab4a8d9a87b099304a8629deea0b4b0a1 (diff)
downloadperlweeklychallenge-club-c5ca130343e62834e6079e43b5cb9588ce0243b1.tar.gz
perlweeklychallenge-club-c5ca130343e62834e6079e43b5cb9588ce0243b1.tar.bz2
perlweeklychallenge-club-c5ca130343e62834e6079e43b5cb9588ce0243b1.zip
- Added solutions by Eric Cheung.
- Added solutions by Ulrich Rieke. - Added solutions by Lukas Mai. - Added solutions by Andrew Shitov. - Added solutions by Feng Chang. - Added solutions by Alexander Karelas. - Added solutions by Simon Proctor. - Added solutions by E. Choroba. - Added solutions by Andreas Mahnke. - Added solutions by Kjetil Skotheim. - Added solutions by PokGoPun. - Added solutions by W. Luis Mochan. - Added solutions by Mark Anderson. - Added solutions by David Ferrone. - Added solutions by Peter Meszaros. - Added solutions by Thomas Kohler. - Added solutions by Peter Campbell Smith.
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))