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.
MaJJ
Posts: 49
Joined: Tue Oct 14, 2008 12:14 am

Problem 004

Post by MaJJ »

Hi,
I am stuck again. !@#$% :D

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
Expand
698896
, 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
Expand
580085 (995*583)
, 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?
Image
Image
User avatar
Georg
Posts: 157
Joined: Mon Jan 21, 2008 7:00 am
Location: Mannheim, Germany
Contact:

Re: Problem 4 - palindroms

Post 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.
User avatar
uws8505
Posts: 58
Joined: Tue Sep 30, 2008 3:13 pm
Location: South Korea

Re: Problem 4 - palindroms

Post 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),...
Math and Programming are complements
MaJJ
Posts: 49
Joined: Tue Oct 14, 2008 12:14 am

Re: Problem 4 - palindroms

Post 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
Expand
(100,100)
Last edited by MaJJ on Wed Oct 15, 2008 1:53 pm, edited 2 times in total.
Image
Image
MaJJ
Posts: 49
Joined: Tue Oct 14, 2008 12:14 am

Re: Problem 4 - palindroms

Post by MaJJ »

Ha! Got it :) I just had to let the program show me all the palindroms.

Thanks!
Image
Image
badperson
Posts: 4
Joined: Fri Jan 09, 2009 8:03 pm

noob: issue with problem 4

Post 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
quilan
Posts: 182
Joined: Fri Aug 03, 2007 11:08 pm

Re: noob: issue with problem 4

Post 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.
ex ~100%'er... until the gf came along.
Image
User avatar
Georg
Posts: 157
Joined: Mon Jan 21, 2008 7:00 am
Location: Mannheim, Germany
Contact:

Re: noob: issue with problem 4

Post by Georg »

The main problem is to identify the maximum correctly.
jessicasco
Posts: 2
Joined: Tue Mar 10, 2009 10:13 am

Re: Problem 004

Post 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. :D :D
Last edited by rayfil on Wed Mar 11, 2009 4:02 am, edited 1 time in total.
Reason: Removed the second identical post made within minutes of this one.
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 004

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

Re: Problem 004

Post by hk »

Just to make it clear:
Integers are written without leading zeros. This applies to all Project Euler problems unless explicitly stated otherwise.
Image
War ruins the life and health of untold numbers of innocent children.
jessicasco
Posts: 2
Joined: Tue Mar 10, 2009 10:13 am

Re: Problem 004

Post by jessicasco »

got it.

now i realize i am wrong.
MoHSalim
Posts: 10
Joined: Mon Jul 13, 2009 2:08 pm

Problem 004 (WARNING: NEWBIE)

Post 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?
User avatar
Georg
Posts: 157
Joined: Mon Jan 21, 2008 7:00 am
Location: Mannheim, Germany
Contact:

Re: Problem 4 (WARNING: NEWBIE)

Post by Georg »

This line

Code: Select all

for(int k = 999; 999>=100; i--)
and more.
MoHSalim
Posts: 10
Joined: Mon Jul 13, 2009 2:08 pm

Re: Problem 004 (WARNING: NEWBIE)

Post by MoHSalim »

Sorry. I already fixed it a while ago and forgot to post here. Thanks anyways, you're awesome. :D
User avatar
Georg
Posts: 157
Joined: Mon Jan 21, 2008 7:00 am
Location: Mannheim, Germany
Contact:

Re: Problem 004 (WARNING: NEWBIE)

Post by Georg »

You should edit your post and delete the source code.
pbear
Posts: 1
Joined: Sat Sep 26, 2009 1:17 am

Re: Problem 004

Post 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
TripleM
Posts: 384
Joined: Fri Sep 12, 2008 3:31 am

Re: Problem 004

Post 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.
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 004

Post 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.
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
theslimzmassive
Posts: 1
Joined: Fri Jan 08, 2010 10:25 am

Problem 4 possible error

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