aboutsummaryrefslogtreecommitdiff
path: root/challenge-288/zapwai/python/ch-1.py
diff options
context:
space:
mode:
authorDavid Ferrone <zapwai@gmail.com>2024-09-23 11:56:29 -0400
committerDavid Ferrone <zapwai@gmail.com>2024-09-23 11:56:29 -0400
commit2f5a634972c673db4d80141ce72c09b713b7200f (patch)
treef85bd1a65172df7e83822fb740bd80eceb96574b /challenge-288/zapwai/python/ch-1.py
parent5e8f04914943ac3a673d64d31ef0dfdec912a0bb (diff)
downloadperlweeklychallenge-club-2f5a634972c673db4d80141ce72c09b713b7200f.tar.gz
perlweeklychallenge-club-2f5a634972c673db4d80141ce72c09b713b7200f.tar.bz2
perlweeklychallenge-club-2f5a634972c673db4d80141ce72c09b713b7200f.zip
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)
+