From fc52f6b569892b44d0f934ae795c199f2b7d3a53 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 2 Nov 2021 00:41:39 +0100 Subject: Python solutions for week 137 --- challenge-137/abigail/python/ch-2.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 challenge-137/abigail/python/ch-2.py (limited to 'challenge-137/abigail/python/ch-2.py') diff --git a/challenge-137/abigail/python/ch-2.py b/challenge-137/abigail/python/ch-2.py new file mode 100644 index 0000000000..8e27559fbf --- /dev/null +++ b/challenge-137/abigail/python/ch-2.py @@ -0,0 +1,29 @@ +#!/opt/local/bin/python + +# +# See ../README.md +# + +# +# Run as: python ch-2.py < input-file +# + +import fileinput + +def reverse (num): + rev = 0 + while num > 0: + rev = rev * 10 + (num % 10) + num = num // 10 + return rev + + +def ly (num): + if num >= 10000000: + return 1 + if num == reverse (num): + return 0 + return ly (num + reverse (num)) + +for number in fileinput . input (): + print (ly (int (number))) -- cgit