I'm hoping this is the last question I have to ask for this particular Project Euler problem. I'm not sure this is the place to ask this question so I apologize in advance if it isn't.
I had finally decided I was not going to get the answer that I needed by hand and decided to let the computer do the work instead. My plan involved generating Pythagorean quadruples using a parameterization on Wikipedia:
$$a=m^2+n^2-p^2-q^2,b=2(mq+np),c=2(nq-mp),d=m^2+n^2+p^2+q^2$$ with the condition that $m,n,p$, and $q$ are non-negative integers with $\gcd(m,n,p,q)=1$ and $m+n+p+q$ is odd. Supposedly, this can generate all primitive quadruples. However, I've noticed some problems. Can I work around them or do I just have to deal with it?
First of all, I haven't been able to figure out a way to generate 4 integers with greatest common divisor of 1. Do I just need to generate and test each set of numbers?
Second, if possible, I'd like to avoid repeats and values that aren't positive and I'm not sure what the best way would be. If I'm not mistaken, I can avoid 0's by only including 1 value of 0 among $m,n,p,$ and $q$. Avoiding negatives is a little trickier. When trying to do it on paper, I'd partition the set of 4 numbers into pairs. Whichever one had the greater sum of squares would be $m$ and $n$. Then I'd need to test the possible pairings to ensure that $nq>mp$. The repeats question is a bit trickier still, but I imagine it's something to do with $d^2-a^2=4(m^2+n^2)(p^2+q^2)$?
Finally, I've noticed that making sure that $m,n,p$ and $q$ do not share a common factor is not enough to ensure that the quadruple is actually primitive. For example, one of the cases I tested by hand was $(m,n,p,q)=(1,7,3,4)$ which generates the quadruple $25^2+50^2+50^2=75^2$. Is there any way to prevent this from occurring? I'm starting to think maybe the parameterization that involves factoring isn't looking so bad after all...