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.
-
Genemos
- Posts: 3
- Joined: Wed Jul 20, 2011 8:41 pm
Re: Problem 004
True enough, an anagram is a palindromic word?
EDIT: Ahh, recalled now, ty.
EDIT: Ahh, recalled now, ty.
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
http://en.wikipedia.org/wiki/Anagram
http://en.wikipedia.org/wiki/Palindrome
In a palindrome the word or number reads the same from left to right as from right to left.
http://en.wikipedia.org/wiki/Palindrome
In a palindrome the word or number reads the same from left to right as from right to left.

War ruins the life and health of untold numbers of innocent children.
-
Shreyeder
- Posts: 2
- Joined: Wed Nov 07, 2012 4:32 pm
[CODE PRESENT FOR HELP!]Slight error in answer in Q4
This is my code for problem 4. However, with all the answers my output gives me, the THIRD LAST ONE is the accepted solution. Please help me out. I am posting the code in JAVA. (My last 2 answers not being accepted are XXXX and XXXX)
class PE4
{
public void main()
{
snip
System.out.println("answer is the 3rd last option. Why?");
}
}
class PE4
{
public void main()
{
snip
System.out.println("answer is the 3rd last option. Why?");
}
}
-
thundre
- Posts: 356
- Joined: Sun Mar 27, 2011 10:01 am
Re: [CODE PRESENT FOR HELP!]Slight error in answer in Q4
Wrong forum. But...
The reason those other numbers aren't correct is that the question asks for the largest palindrome, not the last one you happen to find.
The reason those other numbers aren't correct is that the question asks for the largest palindrome, not the last one you happen to find.

- rayfil
- Administrator
- Posts: 1412
- Joined: Sun Mar 26, 2006 5:30 am
- Location: Quebec, Canada
- Contact:
Re: Problem 004
@ Shreyeder
First, we understand you are new to this forum. You must realize that this is an open forum open to all members, who may not have yet solved some of the problems. You must thus be careful about what you post.
Secondly, any question related to published problems must be posted in an existing thread (if it does exist). Problem numbers below 100 are padded with leading 0's to make all of them a 3-digit number. Searching for the relevant thread and reading the existing posts can often answer your question. And, those threads are NOT for posting code nor results. Read the big red sign before posting.
Welcome to Project Euler and to this forum.
First, we understand you are new to this forum. You must realize that this is an open forum open to all members, who may not have yet solved some of the problems. You must thus be careful about what you post.
Secondly, any question related to published problems must be posted in an existing thread (if it does exist). Problem numbers below 100 are padded with leading 0's to make all of them a 3-digit number. Searching for the relevant thread and reading the existing posts can often answer your question. And, those threads are NOT for posting code nor results. Read the big red sign before posting.
Welcome to Project Euler and to this forum.
When you assume something, you risk being wrong half the time.
-
Shreyeder
- Posts: 2
- Joined: Wed Nov 07, 2012 4:32 pm
Re: Problem 004
My apologies. Thanks a lot for the clarification and to look up forums for particular problems (Y)
-
johanafm
- Posts: 2
- Joined: Wed Oct 16, 2013 8:20 pm
Problem 004
I could use a little help to find out where I go wrong…
The parts I'm working with are
The first 3 (rejected) palindromes I find, alongside their respective factorizations, are
749947 - 869, 863
Any suggestions are welcome. I'm trying to avoid spoilers, but please let me know if I need to post more information.
The parts I'm working with are
- highestPalindrome - returns the next lower palindrom from input
- factorize - returns the biggest factor below 1000 of its input
The first 3 (rejected) palindromes I find, alongside their respective factorizations, are
- 997799 - 11, 90709
- 996699 - 33, 30203
- 995599 - 319, 3121
749947 - 869, 863
Any suggestions are welcome. I'm trying to avoid spoilers, but please let me know if I need to post more information.
- hk
- Administrator
- Posts: 12832
- Joined: Sun Mar 26, 2006 10:34 am
- Location: Haren, Netherlands
Re: Problem 004
I think you are new here but topics in this forum are named Problem xxx. For this problem that is Problem 004.
Further you're not supposed to make a new topic for a problem if there already exists one.
Perhaps you can find your answer in the pages above.
Further you're not supposed to make a new topic for a problem if there already exists one.
Perhaps you can find your answer in the pages above.

War ruins the life and health of untold numbers of innocent children.
-
johanafm
- Posts: 2
- Joined: Wed Oct 16, 2013 8:20 pm
Re: Problem 004
Sorry about that and thank you for moving my post.
Since posting I've come to realize that my error was with finding the correct factors for each palindrome. Then I realized that instead of "building" the factors by prime factorization, it would be better to start looking for divisors from the other end.
Since posting I've come to realize that my error was with finding the correct factors for each palindrome. Then I realized that instead of "building" the factors by prime factorization, it would be better to start looking for divisors from the other end.
-
sohamc
- Posts: 1
- Joined: Sun Mar 09, 2014 2:54 pm
Problem 004
Just started with Project Euler and don't quite know if this question has asked before in the forum.
http://projecteuler.net/problem=4
Can anyone explain to me what does the statement mean by "largest palindrome made from the product of two 2-digit numbers"...I mean that is supposed to be 9779(11*77...two 2-digit numbers)...then how is it 9009??
Thanks in advance!!
http://projecteuler.net/problem=4
Can anyone explain to me what does the statement mean by "largest palindrome made from the product of two 2-digit numbers"...I mean that is supposed to be 9779(11*77...two 2-digit numbers)...then how is it 9009??
Thanks in advance!!
- Marcus_Andrews
- Administrator
- Posts: 1637
- Joined: Wed Nov 09, 2011 5:23 pm
-
yth
- Posts: 3
- Joined: Tue Jul 29, 2014 12:01 am
-
Svartskägg
- Posts: 55
- Joined: Thu Mar 29, 2012 12:55 pm
- Location: Sweden
Re: Problem 004
I think mine is O(n log n).yth wrote:Is there are a more efficient solution to this problem than O(n^2)?

320641_5486fc18ea1dcc4e9a8f29c7677a5c19 <-- my friend key
-
thundre
- Posts: 356
- Joined: Sun Mar 27, 2011 10:01 am
Re: Problem 004
I think all general algorithms will take O(n2), but the clever ones have a much lower constant.yth wrote:Is there are a more efficient solution to this problem than O(n^2)?
You could go crazy optimizing. For example, 10 is an even base. If you assume the first digit of the answer is 9, the last digit must also be 9. Then you can infer it's either xx1 * xx9 or xx3 * xx3. However, if it turns out there isn't an answer beginning with 9, you might have just wasted a chunk of time...

-
yth
- Posts: 3
- Joined: Tue Jul 29, 2014 12:01 am
Re: Problem 004
I think someone posted their ran speed for solving this in a few ms range. That's 50+ times faster than my code. I already restrict my code to only check the highest 50 numbers or so. That's why I was wondering if there is something more efficient.
-
Svartskägg
- Posts: 55
- Joined: Thu Mar 29, 2012 12:55 pm
- Location: Sweden
Re: Problem 004
That's slow. My code takes 10 μs and checks 500 numbers.yth wrote:I think someone posted their ran speed for solving this in a few ms range. That's 50+ times faster than my code.
Which programming language are you using?

320641_5486fc18ea1dcc4e9a8f29c7677a5c19 <-- my friend key
-
Falke88
- Posts: 2
- Joined: Sun Aug 03, 2014 1:29 pm
Re: Problem 004
Its not about how you calculate the products - in which order. Just be sure to return the highest palindrom number "at the end".
-
nanogyth
- Posts: 2
- Joined: Sat Jul 26, 2014 2:51 pm
Re: Problem 004
or xx7 * xx7thundre wrote:If you assume the first digit of the answer is 9, the last digit must also be 9. Then you can infer it's either xx1 * xx9 or xx3 * xx3.
-
thundre
- Posts: 356
- Joined: Sun Mar 27, 2011 10:01 am
Re: Problem 004
Of course.nanogyth wrote:or xx7 * xx7thundre wrote:If you assume the first digit of the answer is 9, the last digit must also be 9. Then you can infer it's either xx1 * xx9 or xx3 * xx3.
(Doh!)
-
youssef
- Posts: 2
- Joined: Thu Aug 14, 2014 12:48 am
Re: Problem 004
Hi everybody,
so i just started learnig python (i 've never learned any languages before) a couple days ago, and i'm stuck on problem 004
so I was wandering if you gus could help me figuring out what's wrong with my code,
here it is:(btw i tried making a program thatt would work not only for three digits numbers.. maybe I souldn't have?, i know it's certainly not optimal and a little bit far fetched)
(btw english is not my native language so i'm sorry for any mistake you'll find)
first i have tried creating a function that gives me the inverse of a given list, this one works perfectly I think, the problemen is with the second one:
-------------------------------------------------------------------------------------------------------------------
<code removed by moderator: see the big red banner on top>
--------------------------------------------------------------------------------------------------------------------------------
the problem is that it doesn't work at all for example :
palindrome(1) gives me
['1']
['2']
['3']
['4']
['5']
['6']
['7']
['8']
['9']
['0', '1'] (now this is the inverse list of 10)
['2', '1'] (of 12)
['4', '1']
['6', '1']
['8', '1']
['1', '2'] (of 21 which is the next j*3 bigger than any j*2 that is 18...)
['4', '2']
['7', '2']
['8', '2']
['2', '3']
['6', '3']
['0', '4']
['5', '4']
['8', '4']
['4', '5']
['6', '5']
['3', '6']
['4', '6']
['2', '7']
Please help me
if you can .. why my code is wrong, or just any advice you'd have for me,
Ps i don't know if i can post any fragment of code here, but since it doesn't work i tought it would be okay
i didn't manage to hide it
so i just started learnig python (i 've never learned any languages before) a couple days ago, and i'm stuck on problem 004
so I was wandering if you gus could help me figuring out what's wrong with my code,
here it is:(btw i tried making a program thatt would work not only for three digits numbers.. maybe I souldn't have?, i know it's certainly not optimal and a little bit far fetched)
(btw english is not my native language so i'm sorry for any mistake you'll find)
first i have tried creating a function that gives me the inverse of a given list, this one works perfectly I think, the problemen is with the second one:
-------------------------------------------------------------------------------------------------------------------
<code removed by moderator: see the big red banner on top>
--------------------------------------------------------------------------------------------------------------------------------
the problem is that it doesn't work at all for example :
palindrome(1) gives me
['1']
['2']
['3']
['4']
['5']
['6']
['7']
['8']
['9']
['0', '1'] (now this is the inverse list of 10)
['2', '1'] (of 12)
['4', '1']
['6', '1']
['8', '1']
['1', '2'] (of 21 which is the next j*3 bigger than any j*2 that is 18...)
['4', '2']
['7', '2']
['8', '2']
['2', '3']
['6', '3']
['0', '4']
['5', '4']
['8', '4']
['4', '5']
['6', '5']
['3', '6']
['4', '6']
['2', '7']
Please help me
Ps i don't know if i can post any fragment of code here, but since it doesn't work i tought it would be okay
i didn't manage to hide it