Originally Posted by

**aesguitar**
... efficient...

I think the most important thing is to have something that works. (Which you apparently do.)

Now, thinking about efficiency without basically changing your approach, I have a couple of observations:

First of all, the way that you are doing it, at the end of your discovery loop, each entry in your

*triangles* array will have a value equal to two times the number of triangles with that perimeter. That is because, for each side set (a, b, c) in the ArrayList for that perimeter, there will be an entry (b, a, c), corresponding to a congruent triangle. (Note that there are no integer right triangles that have two equal sides.)

Therefore, the index of largest element value in your

*triangles *array already indicates the answer to the problem as stated. In fact, unless you want to print out the side sets for a given perimeter, you don't actually need any ArrayLists at all. (Ability to print out solutions is a nice touch, but not really part of the problem assignment.)

Secondly, you can calculate the

*triangles* array element values (and create the ArrayLists if you want to) with no duplicates by changing your discovery loops to something like

for(int a = 1; whatever...)
{
for(int b = a+1; whatever...)
{

So, not only is the corrective loop (to remove duplicates) no longer necessary, but the discovery loop runs faster. You can still create the ArrayLists if you want to print the side sets, and you don't have to worry about duplicates at all.

There may be other ways to improve performance, as you can see by referring to the Project Euler list of comments for that problem, which you can access after you have submitted the correct answer. In my opinion, that's the real value of Project Euler: Seeing how others approach the problem.

Cheers!

Z