Problem 004
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.
See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
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
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.
- Francky
- Posts: 90
- Joined: Sat May 07, 2011 3:49 pm
- Location: South of France
Re: Problem 004
I've found a great trick to limitate the search in special triangle, once a candidate is found.
Who's interrested ?
Who's interrested ?
Entia non sunt multiplicanda praeter necessitatem-
Comfyasabadger
- Posts: 2
- Joined: Fri Jun 10, 2011 9:52 am
Problem 004 C#
Is there a forum for code discussion for people that have solved the problems?
Using C# for the problems and as I've got a lot to learn was looking for feed back and efficiency suggestions.
Using C# for the problems and as I've got a lot to learn was looking for feed back and efficiency suggestions.
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 004
For every problem there is a forum when you solved the problem. However the forums for the lower numbered forums are locked and read only. (Otherwise there would be thousands and thousands of posts to wade through).
The idea is that you read that forum to find out if you can improve on your algoritm.
Also for the lower numbered problems there is a pdf available where you can read more about the problem.
That is the pdf icon to the right of the green tick that indicates that you solved the problem.
The idea is that you read that forum to find out if you can improve on your algoritm.
Also for the lower numbered problems there is a pdf available where you can read more about the problem.
That is the pdf icon to the right of the green tick that indicates that you solved the problem.

War ruins the life and health of untold numbers of innocent children.
-
Comfyasabadger
- Posts: 2
- Joined: Fri Jun 10, 2011 9:52 am
-
MarekDudek
- Posts: 2
- Joined: Sun Jul 03, 2011 12:01 am
Re: Problem 004
I have better solution that one mentioned in overview.
One that never checks two numbers that were previously checked and that guarantees that first palindrome found is largest.
Thread is locked, I cannot post it. What to do?
One that never checks two numbers that were previously checked and that guarantees that first palindrome found is largest.
Thread is locked, I cannot post it. What to do?
-
MarekDudek
- Posts: 2
- Joined: Sun Jul 03, 2011 12:01 am
-
MarekDudek
- Posts: 2
- Joined: Sun Jul 03, 2011 12:01 am
- Francky
- Posts: 90
- Joined: Sat May 07, 2011 3:49 pm
- Location: South of France
Re: Problem 004
My (uncompiled) python code is under 3ms, and I can find for n=9 instead of n=3. (9×9 digits -> 18-digits palindromic number)
See previous posts.
EDIT : I'd optimized it a little.
0.26ms for n=3 (original problem)
112ms for n=9
EDIT : One more optimization (for high numbers)
0.28ms for n=3 (original problem)
33ms for n=9
and for n=11, wich is a much much harder problem, we can proove in 3.5 second
that 99999581723 × 99999321213 = 9999890293883920989999
is the biggest palindromic number, product of two 11-digit numbers.
Who can give the answer for n=13 ? (I need 2 minutes to proove the answer given after 52s)
------
EDIT : my second algo is wrong.
LucyHedgeHog found better and faster !!! (see forum after solving problem)
See previous posts.
EDIT : I'd optimized it a little.
0.26ms for n=3 (original problem)
112ms for n=9
EDIT : One more optimization (for high numbers)
0.28ms for n=3 (original problem)
33ms for n=9
and for n=11, wich is a much much harder problem, we can proove in 3.5 second
that 99999581723 × 99999321213 = 9999890293883920989999
is the biggest palindromic number, product of two 11-digit numbers.
Who can give the answer for n=13 ? (I need 2 minutes to proove the answer given after 52s)
------
EDIT : my second algo is wrong.
LucyHedgeHog found better and faster !!! (see forum after solving problem)
Last edited by Francky on Sun Sep 25, 2011 1:22 pm, edited 1 time in total.
Entia non sunt multiplicanda praeter necessitatem-
ehicks
- Posts: 3
- Joined: Fri Jul 08, 2011 5:49 am
Re: Problem 004
My code works perfectly for two digits, and I get what seems to be a valid answer for multiplying two 3 digit numbers. My family members got the same answer using multiple algorithms and multiple programs (Matlab and Exel). But the website keeps rejecting it. Is it possible the website is wrong?
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
Re: Problem 004
No.ehicks wrote:Is it possible the website is wrong?
Does your program stop at the first palindrome it finds? Think about whether it could be possible to get a larger palindrome using a number your program hasn't tested.
-
ehicks
- Posts: 3
- Joined: Fri Jul 08, 2011 5:49 am
Re: Problem 004
My program starts from the largest possible value (999*999) and looks backward for palindromes. I'm just frustrated because I found the same result with multiple approaches algorithms (but all starting from the greatest). Do you have any idea what could've gone wrong? Maybe when I turn each number into a string so that I can flip it and compare it to itself, the program misses some? I don't see why that would happen... Any ideas?
- jaap
- Posts: 588
- Joined: Tue Mar 25, 2008 3:57 pm
- Contact:
- Francky
- Posts: 90
- Joined: Sat May 07, 2011 3:49 pm
- Location: South of France
Re: Problem 004
+1, but with a clever test, you'll could stop few steps later.jaap wrote:Does your program stop at the first palindrome it finds? Don't do that.
(it was my first algo, now I found a new way, much faster)
Entia non sunt multiplicanda praeter necessitatem-
ehicks
- Posts: 3
- Joined: Fri Jul 08, 2011 5:49 am
Re: Problem 004
THANK YOU!!! I didn't even realize the way I set up my loop it DID stop after finding the first one NOT the largest one, woopsjaap wrote:Does your program stop at the first palindrome it finds? Don't do that.
-
jey1234
- Posts: 1
- Joined: Fri Jul 29, 2011 6:16 am
Problem 004
I am new to programming. I tried to solve #4 with python. But the solution is not right. Any ideas? Thanks..
from sets import Set
snip
from sets import Set
snip
Last edited by rayfil on Thu Aug 04, 2011 3:31 am, edited 1 time in total.
Reason: No code or results allowed, not even for beginners or new members.
Reason: No code or results allowed, not even for beginners or new members.
-
thundre
- Posts: 356
- Joined: Sun Mar 27, 2011 10:01 am
Re: Problem 004
New to this site too? At the top of the page it says in big dancing letters "don't post any code fragments or results."jey1234 wrote:I am new to programming. I tried to solve #4 with python. But the solution is not right. Any ideas? Thanks..
It looks like you're making a list of all products of 3-digit numbers and then printing it out, or maybe just printing out the first one -- sorry I don't know python -- 101*101 = 10201? That happens to be a palindrome but not the largest.

-
Srija
- Posts: 1
- Joined: Wed Sep 21, 2011 12:50 pm
Largest Palindrome of two digit numbers
HI everyone i am trying to solve problem4 in c++
the below program is to find the palindrome of the product of 2 digit numbers(up to 10*11 for trails).
snip
the above code works for all that i need except for the largest palindrome.
my algorithm is like
1. Product each combination
2. use palindrome function to check the result is palindrome or not if multiplication res is >10 and print the palindrome.
3.here i have to check for the largest number by comparing with the previous number. so i have stored the previous value in res1 variable. and i am comparing the res and res1 variables
according to my logic it checks lastly (88<99) that is true
now the problem is how to print the last vale stored in res variable????
if anybody helps i would be thankful
the below program is to find the palindrome of the product of 2 digit numbers(up to 10*11 for trails).
snip
the above code works for all that i need except for the largest palindrome.
my algorithm is like
1. Product each combination
2. use palindrome function to check the result is palindrome or not if multiplication res is >10 and print the palindrome.
3.here i have to check for the largest number by comparing with the previous number. so i have stored the previous value in res1 variable. and i am comparing the res and res1 variables
according to my logic it checks lastly (88<99) that is true
now the problem is how to print the last vale stored in res variable????
if anybody helps i would be thankful
Last edited by rayfil on Thu Sep 22, 2011 12:58 am, edited 1 time in total.
Reason: don't post any code fragments or results.
Reason: don't post any code fragments or results.
- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: Largest Palindrome of two digit numbers
Although you are new to this forum, the red banner should have been sufficiently apparent for you to notice.
This forum is not designed to post code but primarily to inquire about potential misunderstanding of problem descriptions. Posts related to specific problem numbers should be made in the related thread. For ease of searching, problem numbers below 100 are padded with leading 0's to get 3 digits. In your case, it would be Problem 004. Your post has thus been transferred to the proper thread. You may find some useful info in that thread.
This forum is not designed to post code but primarily to inquire about potential misunderstanding of problem descriptions. Posts related to specific problem numbers should be made in the related thread. For ease of searching, problem numbers below 100 are padded with leading 0's to get 3 digits. In your case, it would be Problem 004. Your post has thus been transferred to the proper thread. You may find some useful info in that thread.
When you assume something, you risk being wrong half the time.
-
Genemos
- Posts: 3
- Joined: Wed Jul 20, 2011 8:41 pm
Re: Problem 004
I am a bit stuck on this problem, I use C++ to program but I think the problem I have is that I have no idea how to describe/check if a number is an palindrome or not. I try to "learn as I go" and I realise that I do not yet know that much, but I feel entierly stuck on this problem, I don't have much of a clue on how to do it.
The problem that I am trying to figure out is that I feel I have to split the number up in order to "rearrange" it, to then check if it is an palindrome or not. Also a bit unsure on how the algorithm should work but think I can work my way around that.
Any tips to sort of get me going?
The problem that I am trying to figure out is that I feel I have to split the number up in order to "rearrange" it, to then check if it is an palindrome or not. Also a bit unsure on how the algorithm should work but think I can work my way around that.
Any tips to sort of get me going?
Last edited by Genemos on Wed Nov 02, 2011 1:27 pm, edited 1 time in total.
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 004
Just a remark. The problem is about palindromic numbers, while you are talking about anagrams.

War ruins the life and health of untold numbers of innocent children.
