aboutsummaryrefslogtreecommitdiff
path: root/challenge-288/zapwai/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-09-23 17:09:54 +0100
committerGitHub <noreply@github.com>2024-09-23 17:09:54 +0100
commita7098451a3fffc4e31ac9e363fe9e17301d0f600 (patch)
treec3889395cbf564fb189be96bff21d254bd930f49 /challenge-288/zapwai/python/ch-1.py
parent12a6acf31c5392b354e117870b6066d8d3e1205b (diff)
parent2f5a634972c673db4d80141ce72c09b713b7200f (diff)
downloadperlweeklychallenge-club-a7098451a3fffc4e31ac9e363fe9e17301d0f600.tar.gz
perlweeklychallenge-club-a7098451a3fffc4e31ac9e363fe9e17301d0f600.tar.bz2
perlweeklychallenge-club-a7098451a3fffc4e31ac9e363fe9e17301d0f600.zip
Merge pull request #10900 from zapwai/branch-for-288
Week 288
Diffstat (limited to 'challenge-288/zapwai/python/ch-1.py')
-rw-r--r--challenge-288/zapwai/python/ch-1.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/challenge-288/zapwai/python/ch-1.py b/challenge-288/zapwai/python/ch-1.py
new file mode 100644
index 0000000000..48ebd7985c
--- /dev/null
+++ b/challenge-288/zapwai/python/ch-1.py
@@ -0,0 +1,29 @@
+def is_pal(s) :
+ r = str(s)[::-1]
+ return (str(s) == r)
+
+def proc(s) :
+ print("Input:", s)
+ n = int(s)
+ found = False
+ step = 1
+ while not found :
+ m = n - step
+ if is_pal(m) :
+ found = True
+ n = m
+ else :
+ m = n + step
+ if is_pal(m) :
+ found = True
+ n = m
+ step += 1
+ print("Output:", n)
+
+s = "123"
+proc(s)
+s = "2"
+proc(s)
+s = "1400"
+proc(s)
+