Jump to content

Followup Hard Math Question: Take a guess!


True

Recommended Posts

I saw this somewhere, and it took a while to compute the answer (not long to write code to solve it), but its pretty easy... :)

Okay, you have x and y. x is from the range of 0 to 1000, y is also from 0 to 1000. You need to multiply all sets of numbers, in both directions (ie. x*y AND y*x, like 50*4 and 4*50, even though both give the same product) and add together those products that are palindromes.

What is the final sum?

Extra credit is the answer this question using products in only one direction (ie 50*4, NOT 4*50, since that same number set has been used already). Programmatically speaking this is really easy, just one more check :)

EDIT: I will include source to find this answer as soon as someone posts the answer.

2ND EDIT: Oops, said it completely wrong... fixed the question :)

Link to comment

gimme a minute i'll give it a shot

edit

ok here's what i got, thoguh i don't see the significance :-P

509033471

here's the code...

#include 
#include 
#include 



bool isPalindrome(int n){
char str[10];
char temp[10];
itoa(n,str,10);
strcpy(temp,strrev(str));
strrev(str);
if (strcmp(temp,str)==0)
{
	cout<		return true;
}
return false;
}
void main(){
int sum=0;
for (int x=0;x<=1000;x++){
	for (int y=0;y<=1000;y++){
		if ((x!=0)&&(y!=0)&&isPalindrome(x*y))
		{

			cout<<"X="<				sum+=x*y;
		}
	}
}
cout<	cout<<"done!";
char temp;
cin>>temp;

}

used 2 strrev calls because it actually changes the string... also the checks that X!=0 and y!=0 does not affect the final answer but saves calculation time :-P

I think the extra credit answer is 255010259 (added a check that x<=y in the main condition)

Kent

Link to comment

Correct on both :)

You already have your C out there... no need for the PHP equiv... besides, mine is quite bloated, I got SOO bored last night I added display of iterations (displays the value at the end of every xxx amount of runs) and something else... damn... all over some stupid math problem... :)

I dont know what so many people think is hard about math... what did that take, 10 minutes if not less? :);) CPUtime probably took the longest chunk of that 10 minutes... :P

Link to comment

I know Cpp is fast... learned when I was 11 :D but because of foster care and constant moving, I didn't have time to keep up with it.

Because of such past experience I easily picked up PHP - literally, in 3 minutes. Now that I am doing PHP I am fine with it, with almost no need for c++ in my life at this moment (or at least creating something new), and I do know reducing such wasteful IO can increase time, maybe it was just the way I coded it or inefficiencies within the operations / functions I used that made my compute time take longer. I dont know... my machine takes about 10 seconds to compute, my webserver takes a minute or so :)

Link to comment
uh uh uh uh uh uh uh uh uh uh uuuuuuuuuuuuuuuuhhhhhhhhhhhhhhh what does this+ sign mean :?:

MODS lock this post it is not needed :?:?:wink:

Please, please, have some humor. Lighten up. The worlds boring enough as it is, what with the seriousness of work, and of new fears of terrorists and all that. We need someone to laugh at, cant it be me and phil? :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...