aboutsummaryrefslogtreecommitdiff
path: root/challenge-288/zapwai/python/ch-1.py
diff options
context:
space:
mode:
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)
+