From d1552c9179c570146ec86d5c91304a61103a0fdb Mon Sep 17 00:00:00 2001 From: Shaun Setlock Date: Mon, 20 Apr 2020 14:45:04 -0400 Subject: [PATCH] Automatic commit performed through alias... --- problems/004_problem.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/problems/004_problem.py b/problems/004_problem.py index 26d8c37..eed6921 100755 --- a/problems/004_problem.py +++ b/problems/004_problem.py @@ -60,10 +60,12 @@ def main(): n_has_token = False test_passed = False palindrome_list=[] - - while (n*m)>0: - # Test for "palindrom-iness" ... + + while (n*m)>1: + + # Loop over all possible pairs of + # integers, testing for "palindrom-iness" ... print("{} * {} = {}".format(n,m,n*m)) test_passed = is_palindrome(n*m) @@ -71,32 +73,28 @@ def main(): palindrome_list.append(n*m) if n_has_token: n -= 1 - if n ==1: + if n ==0: n_has_token = False - n = max_factor + n = m-1 if not n_has_token: m -= 1 - n_has_token = True + if m ==1: + n_has_token = True + m = n-1 + if not test_passed: if n_has_token: n -= 1 - if n ==1: + if n ==0: n_has_token = False - n = max_factor + n = m-1 if not n_has_token: m -= 1 - n_has_token = True - - - - - - print("{}".format(max(palindrome_list))) -# print("{} * {} = {}".format(n,m,n*m)) - -# print("The largest palindrome number which is a product of two numbers of length {} is {} ... ".format(num_digits,num_digits)) - + if m ==1: + n_has_token = True + m = n-1 + print("The largest palindrome number which is a product of two numbers of length {} is {} ... ".format(factor_length,max(palindrome_list))) main() \ No newline at end of file