I threw together a program for this. It's purely brute force, but I don't think that's much of an issue, because the keyspace is so small. If a, b, and c are all different, we can construct 27 (3^3) unique 3-digit numbers from them which are candidates for p, q, and r. Then from these we can choose any 3, with repetition, but order does not matter. That is, p + q + r = r + q + p, etc. So the maximum number of "unique" p + q + r equations that can be built is:
C(27 + 3 - 1, 3) = C(29,3) = 3654
If exactly two out a, b, c are equal to one another, then there are 2^3 = 8 candidates and therefore the unique p, q, r equations are reduced to:
C(8 + 3 - 1, 3) = C(10,3) = 120
And obviously if a = b = c, there is only one possible unique equation p + q + r that can be built.
My program operates according to the process outline above. First it builds the list of candidates for p, q, and r. Afterwards, it iterates over the unique combinations of p, q, and r, checking for sums.
I'm sure this could be made more efficient by various means. Offhand, you could certainly exploit parity rules. Divide the candidates into evens and odds. If N is odd, you can test only those combinations containing one odd and two evens, or three odds, etc. However, given that there are most <4k keys to test, the value of such optimizations seems dubious.
My first crack at this was in Python:
http://meriwoker.dyndns.org/~stathol/glade/3by3.pyBut morbid curiosity got the better of me, so I ported it to C++:
http://meriwoker.dyndns.org/~stathol/glade/3by3.cppI included the ability in both progs to loop the algo 10k times with random inputs for profiling purposes:
Python:
Code:
<redacted>@juliet:~# /usr/bin/time ./3by3.py --profile > /dev/null
8.06user 0.01system 0:08.07elapsed 100%CPU (0avgtext+0avgdata 20368maxresident)k
0inputs+0outputs (0major+1388minor)pagefaults 0swaps
C++:
Code:
<redacted>@juliet:~# /usr/bin/time ./3by3-profile > /dev/null
0.07user 0.01system 0:00.08elapsed 102%CPU (0avgtext+0avgdata 4112maxresident)k
0inputs+0outputs (0major+293minor)pagefaults 0swaps
*sigh* It's okay, Python. I still love you. :/