Page 5 of 5

Re: Problem 004

Posted: Thu Aug 14, 2014 2:15 pm
by nicolas.patrois
Python knows how to reverse a list without a function with the slices.

Problem 004 : Largest Palindrome Product

Posted: Fri Jun 22, 2018 6:43 am
by HassenTimol
Hello ,

I would have an important question although it may be seen, for some, a ridiculous question.

The problem 4 state this :

" A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99.
Find the largest palindrome made from the product of two 3-digit numbers. "

My question is the following :

I have found that the answer is <snip>, it is indeed, the product of the two 3-digits numbers, <snip> and <snip>. When I've rum my program, it's the only answer it has given me. However, when I write <snip> as the answer of problem 4, it tells me that's not the correct answer.

I'll let you see my program written on Python :
<code snipped>
Thank you for helping me.

Re: Problem 004

Posted: Fri Jun 22, 2018 10:39 am
by DJohn
Please don't post code or solutions (even wrong ones): see the big red text at the top.

Are you certain that your palindrome() function works? Try testing it with a few numbers that you know are palindromes, and some that you know aren't. There is definitely more than one palindromic product of two three digit numbers! For example, 101*101 = 10201.

Re: Problem 004 : Largest Palindrome Product

Posted: Fri Jun 22, 2018 10:54 am
by hk
A few remarks:
1) don't start a new topic for a problem if there already exists one.
2) Don't post code or solutions (even wrong ones).

3) If you had tested if x is a 6-digit number before running your function essai(x) you could have found the correct answer.

Re: Problem 004

Posted: Sat Sep 05, 2020 10:31 am
by Ontogenes
I just recently completed problem 3, and am now ready to tackle problem 4!

I've thought a lot of how to approach this problem, and I think I could use a couple of hints of how I should get started. When I completed the first three problems, it helped me to divide my solution into smaller scripts that individually performed a single task, and then I would combine these components to solve the problem. In the case of problem 4, I am thinking that I would need a script that can identify if a number is palindromic or not. Does this seem like a reasonable idea, or am I way off track?

I am doing these problems since I am new to programming and using Python as my primary programming language for the moment. So, what do you think, should I start off by writing a script that decides if a number is palindromic or not, or is there anything else I should focus on?

Feedback and hints are much appreciated :)

Re: Problem 004

Posted: Thu Sep 10, 2020 2:56 pm
by pjt33
@Ontogenes, you're looking for a number which has two properties: (1) it's a palindrome; (2) it's a product of two 3-digit numbers. There are three basic approaches: (A) generate all numbers and test both properties; (B) generate all numbers having the first property and test whether they have the second property; (C) generate all numbers having the second property and test whether they have the first property.

Both (B) and (C) are obviously preferable to (A), provided you can figure out how to do them without it being really (A) in disguise. It will often not be obvious which of (B) or (C) is better unless you try both and compare them.

TL;DR: your approach is reasonable, but not the only reasonable one. When you've found the solution, you might want to try other approaches for comparison.