Problem 004

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
User avatar
nicolas.patrois
Posts: 118
Joined: Fri Jul 26, 2013 4:54 pm
Contact:

Re: Problem 004

Post by nicolas.patrois »

Python knows how to reverse a list without a function with the slices.
Image
HassenTimol
Posts: 1
Joined: Fri Jun 22, 2018 6:34 am

Problem 004 : Largest Palindrome Product

Post 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.
DJohn
Posts: 90
Joined: Sat Oct 11, 2008 12:24 pm

Re: Problem 004

Post 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.
User avatar
hk
Administrator
Posts: 12832
Joined: Sun Mar 26, 2006 10:34 am
Location: Haren, Netherlands

Re: Problem 004 : Largest Palindrome Product

Post 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.
Image
War ruins the life and health of untold numbers of innocent children.
User avatar
Ontogenes
Posts: 1
Joined: Sun Aug 30, 2020 2:25 pm

Re: Problem 004

Post 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 :)
pjt33
Posts: 140
Joined: Mon Oct 06, 2008 6:14 pm

Re: Problem 004

Post 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.
Post Reply