Page 1 of 5
Problem 004
Posted: Wed Oct 15, 2008 8:14 am
by MaJJ
Hi,
I am stuck again. !@#$%
I have done code that finds if number in a variable is palindromic, but there is probably an error with the code that tries all combinations of numbers.
I am doing it with WHILE cycle - it repeats the code until there is a palindromic number or one of numbers that I am multipling, is < 100.
When I tried code that lowers only one of the numbers, it found
, but it's not enough.
When I tried code that lowest one of the numbers and if it's below 100, it returns it back to 999 and lowers second number. It found
, which is even lower. But this code (if done right) should try all combinations, so ... it must be wrongly written ...
I tried to edit that "palindromic requirement" for 4-digit palindroms and other code for 2-digit numbers (if below 10, return to 99), and it found that 9009 (result of example problem). So maybe this code is right, maybe not.
Any ideas? Should I try some completely different algorithm to multiply numbers?
Re: Problem 4 - palindroms
Posted: Wed Oct 15, 2008 8:35 am
by Georg
"I am doing it with WHILE cycle - it repeats the code until there is a palindromic number "
"But this code (if done right) should try all combinations"
This is a contradiction.
Re: Problem 4 - palindroms
Posted: Wed Oct 15, 2008 11:24 am
by uws8505
It would be better if you test (999,999) (999,998) (999,997) (998,998) (999,996) (998,997) and so on
rather than (999,999),...,(999,100),(998,999),...
Re: Problem 4 - palindroms
Posted: Wed Oct 15, 2008 1:47 pm
by MaJJ
2 georg - this code goes from higher numbers, so it should stop at the highest, or not?
EDIT: It shouldn't, now I know that 
I will try to make it go to the end
Re: Problem 4 - palindroms
Posted: Wed Oct 15, 2008 1:52 pm
by MaJJ
Ha! Got it

I just had to let the program show me all the palindroms.
Thanks!
noob: issue with problem 4
Posted: Fri Jan 09, 2009 8:07 pm
by badperson
Hi,
I'm just going thru the problems, just getting started out, and my answer to number 4 was rejected, but I'm sure it's right. I double checked it on the calculator, and the same algorithm works with the 2-digit example given in the problem description.
Is it some kind of trick answer I'm not getting?
bp
Re: noob: issue with problem 4
Posted: Fri Jan 09, 2009 9:00 pm
by quilan
No trick on this one; it's fairly straight forward. If you want to PM your answer, I can let you know if there's anything incorrect about it.
Re: noob: issue with problem 4
Posted: Sat Jan 10, 2009 2:33 pm
by Georg
The main problem is to identify the maximum correctly.
Re: Problem 004
Posted: Tue Mar 10, 2009 10:20 am
by jessicasco
I am a new member, and I think I have a lot to learn.
Now I want to say that the overview of problem 004 has a mistake.
It's the function "reverse",
may be the point of the problem is not at this function, but I still have to say
this so it can be changed to a better version.
If n is 1000;
the return value of the reverse function is 1;
surely not the intended answer. the author made this little mistake.

Re: Problem 004
Posted: Tue Mar 10, 2009 10:50 am
by TripleM
Why would the reverse of 1000 not be 1? When I reverse 1000, I get 0001, which I can't see to be any number other than 1.
Re: Problem 004
Posted: Tue Mar 10, 2009 10:58 am
by hk
Just to make it clear:
Integers are written without leading zeros. This applies to all Project Euler problems unless explicitly stated otherwise.
Re: Problem 004
Posted: Sat Mar 21, 2009 5:26 am
by jessicasco
got it.
now i realize i am wrong.
Problem 004 (WARNING: NEWBIE)
Posted: Mon Jul 13, 2009 2:10 pm
by MoHSalim
This is the code I got:
(code snipped)
//The Exceptions I receive are below
----jGRASP exec: java ProblemFour
Exception in thread "main" java.lang.NumberFormatException: For input string: "-"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:474)
at java.lang.Integer.parseInt(Integer.java:497)
at Palindromic.isPalindromic(Palindromic.java:26)
at ProblemFour.main(ProblemFour.java:16)
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
//What's wrong with my life/program?
Re: Problem 4 (WARNING: NEWBIE)
Posted: Mon Jul 13, 2009 6:27 pm
by Georg
Re: Problem 004 (WARNING: NEWBIE)
Posted: Tue Jul 14, 2009 3:42 am
by MoHSalim
Sorry. I already fixed it a while ago and forgot to post here. Thanks anyways, you're awesome.

Re: Problem 004 (WARNING: NEWBIE)
Posted: Tue Jul 14, 2009 8:50 am
by Georg
You should edit your post and delete the source code.
Re: Problem 004
Posted: Sat Sep 26, 2009 1:26 am
by pbear
What's wrong with this code?
Code: Select all
39 for( x = 999; x >= 100; x-- ) {
40 for( y = 999; y >= x; y-- ) {
41 r = x * y;
42 printf("%u * %u = %u\n", x, y, r);
43
44 if( is_palindrome( r ) ){
45 printf("I has it: %d\n", r);
46 return 0;
47 }
48 }
49 }
It does yield a palindrome of six digits, and I can't see what is wrong here
Re: Problem 004
Posted: Sat Sep 26, 2009 1:41 am
by TripleM
If it yields a palindrome of 6 digits, and it tells you you have the wrong answer, then logically it cannot be the largest.
Re: Problem 004
Posted: Sat Sep 26, 2009 1:47 am
by daniel.is.fischer
Exactly, there are 80 6-digit palindromes larger than what that code returns which are the product of two 3-digit numbers.
Problem 4 possible error
Posted: Fri Jan 08, 2010 10:32 am
by theslimzmassive
Would i be wrong in saying the actual answer to problem 4 is 997799? The accepted answer is < snip >. The question is:
Find the largest palindrome made from the product of two 3-digit numbers.
999*999 = 998001 <- upper limit
so basically
< snip ><997799<(999*999)
ala < snip > is the wrong answer.