True Posted September 27, 2003 Share Posted September 27, 2003 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
RobZGod Posted September 28, 2003 Share Posted September 28, 2003 And i thought 2+2 was hard... Link to comment
Guest Posted September 28, 2003 Share Posted September 28, 2003 i know the anser to 2+2 is................just ask someone Link to comment
RobZGod Posted September 28, 2003 Share Posted September 28, 2003 i know the anser to 2+2 is................just ask someone Gimme a clue, please? Link to comment
Iam A. Spammer Posted September 28, 2003 Share Posted September 28, 2003 In reply to the top post: 7 ! Link to comment
Guest Posted September 28, 2003 Share Posted September 28, 2003 uh uh uh uh uh uh uh uh uh uh uuuuuuuuuuuuuuuuhhhhhhhhhhhhhhh what does this+ sign mean Link to comment
Nub Posted September 28, 2003 Share Posted September 28, 2003 uh uh uh uh uh uh uh uh uh uh uuuuuuuuuuuuuuuuhhhhhhhhhhhhhhh what does this+ sign mean MODS lock this post it is not needed Link to comment
Kent747 Posted September 28, 2003 Share Posted September 28, 2003 gimme a minute i'll give it a shot edit ok here's what i got, thoguh i don't see the significance 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 I think the extra credit answer is 255010259 (added a check that x<=y in the main condition) Kent Link to comment
Guest Posted September 29, 2003 Share Posted September 29, 2003 hey im having a special conversation with rob Link to comment
True Posted September 29, 2003 Author Share Posted September 29, 2003 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... Link to comment
Kent747 Posted September 29, 2003 Share Posted September 29, 2003 cpu time took about 1 -2 seconds for me coded in about 5 mins try compiling it.. i thinkyou'll find that C++ is quite fast also limiting screen displays really improves speed, as I/O is terribly slow Link to comment
True Posted September 29, 2003 Author Share Posted September 29, 2003 I know Cpp is fast... learned when I was 11 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
RobZGod Posted September 29, 2003 Share Posted September 29, 2003 uh uh uh uh uh uh uh uh uh uh uuuuuuuuuuuuuuuuhhhhhhhhhhhhhhh what does this+ sign mean MODS lock this post it is not needed 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
Iam A. Spammer Posted September 29, 2003 Share Posted September 29, 2003 gimme a minute i'll give it a shotedit ok here's what i got, thoguh i don't see the significance 509033471 Damn, I had a feeling that 7 wasn't right! Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now