aboutsummaryrefslogtreecommitdiff
path: root/challenge-289/zapwai/python
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-30 22:00:03 +0100
committerGitHub <noreply@github.com>2024-09-30 22:00:03 +0100
commit4fc5b1d10239d98f05d83c95f22ec6becd111cd5 (patch)
treeec444747cd7c8c4cb47cd11cd248e980eff6b805 /challenge-289/zapwai/python
parente4cdda8a1053c2bcd7d33bbad494158355fd0b3c (diff)
parentef99aabc641bef7ebe24b809e401babda7dfc5fe (diff)
downloadperlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.tar.gz
perlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.tar.bz2
perlweeklychallenge-club-4fc5b1d10239d98f05d83c95f22ec6becd111cd5.zip
Merge pull request #10935 from zapwai/branch-for-289
Week 289
Diffstat (limited to 'challenge-289/zapwai/python')
-rw-r--r--challenge-289/zapwai/python/ch-1.py25
-rw-r--r--challenge-289/zapwai/python/ch-2.py28
2 files changed, 53 insertions, 0 deletions
diff --git a/challenge-289/zapwai/python/ch-1.py b/challenge-289/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..8b520005c1
--- /dev/null
+++ b/challenge-289/zapwai/python/ch-1.py
@@ -0,0 +1,25 @@
+def proc(ints) :
+ print( "Input:", ints)
+ ans = max(ints)
+ new1 = []
+ for i in range(len(ints)):
+ if ints[i] != ans:
+ new1.append(ints[i])
+ if len(new1) > 0 :
+ m2 = max(new1)
+ new2 = []
+ for i in range(len(new1)):
+ if new1[i] != m2:
+ new2.append(new1[i])
+
+ if len(new2) > 0:
+ ans = max(new2)
+ print( "Output:", ans)
+
+ints = [5, 6, 4, 1]
+proc(ints)
+ints = [4, 5]
+proc(ints)
+ints = [1, 2, 2, 3]
+proc(ints)
+
diff --git a/challenge-289/zapwai/python/ch-2.py b/challenge-289/zapwai/python/ch-2.py
new file mode 100644
index 0000000000..f5bd6b88fc
--- /dev/null
+++ b/challenge-289/zapwai/python/ch-2.py
@@ -0,0 +1,28 @@
+import random
+
+def jumble(word) :
+ if len(word) < 4:
+ return word
+ let = list(word)
+ start = let[0]
+ end = let[len(let) - 1]
+ let = let[1:-1]
+ order = []
+ while (len(order) < len(let)) :
+ x = random.randint(0, len(let) - 1)
+ if x not in order:
+ order.append(x)
+ middle = ""
+ for i in order:
+ middle += let[i]
+ q = start + middle + end
+ return q
+
+def proc(s) :
+ print( "Input:", s)
+ words = s.split(" ")
+ new = ' '.join(map(jumble, words))
+ print( "Output:", new)
+
+s = "This supposed Cambridge research is unfortunately an urban legend"
+proc(s)