From 2f5a634972c673db4d80141ce72c09b713b7200f Mon Sep 17 00:00:00 2001 From: David Ferrone Date: Mon, 23 Sep 2024 11:56:29 -0400 Subject: Week 288 --- challenge-288/zapwai/python/ch-1.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-288/zapwai/python/ch-1.py (limited to 'challenge-288/zapwai/python/ch-1.py') 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) + -- cgit