#include <iostream>
usingnamespace std;
int main()
{
int a, b, c;
for(c = 3; c<500 ; c++);
{ cout << "O U T S I D E" << endl;
for(b = 4 ; b<c ; b++)
{ cout << "MIDDLE" << endl;
for( a= 5; a<b; a++)
{ cout << "inside" << endl;
if(a<b && b<c && ((a + b + c) == 1000) && ((a*a + b*b) == c*c) )
goto label;
}
}
}
label:
cout << a << " " << b << " "<< c << endl;
cout << "The Product is: " << a*b*c << endl;
return 0;
}
The code above doesn't even find a true if-condition.
There must be some efficient way of doing that checks all possible combinations of a, b and c.
the goto label is to simply break out of all three loops at once. I know its frowned upon, bit im only using it for the purpose of solving this problem. I wont be publishing this code.
Project Euler is a special case of problem solving which encourages people to solve the problems using their own skills and not those of others.
If you just want the answer then google the problem. There are lots of places where you can defeat the purpose by downloading the programs and answers.
Like Project Euler says, if one problem turns out to be too difficult, just move onto another one.
I understand what u are saying Arslan and many like you and I have suffered but the principle adopted by PE is to avoid other people's fun being spoiled.
I'm not a policeman ( don't want to be either) and I can't stop you from discussing PE problems here so it is up to you. I would feel very sorry for someone who has worked on the problem for weeks to have it undone by inadvertently coming across the key in a public forum such as this.
If you want to know whether you have set it up right then run it and check the answer at the PE site. Sounds cruel but that's the game.
If you get a compile/linker error let us know and we'll help but the methodology is really yours alone.
As you probably know, you only see what other people have done when you succeed and they open the door but only on that problem.
(FWIW I have been stumped on problem 51 for 3 months but I will never ask how to solve it or what the answer is and yet I can get both with google in about 30 seconds. All I've don is consult the questyions page on the PE discussion site - and as always you don't get much help.)
Thank you for kindly explaining it to me. Definitely agree with you on the fun part. The site is absolutely fantastic and working on the problems is really enjoyable.
I guess I'll do my best to figure it out on my own now.
You know what is funny?
You have solved the problem.
Your code works. It gives correct answer if you remove one small syntax problem: look at the line 10. At its end, precisely. There is something which should not be here.
(additionally, do not use endl in loops. It murders perfomance)
EDIT: After removing debug output, yout naive approach is only slightly slower that precomputing all squares and looking for third member of pythagorean triad with binary search. And with removing inner loop (which you do not strictly need), it is even faster.