Bryan wrote:

> Thanks all for the suggestions! I realized something though (sorry for

> that) that may simplify things..

>

> In fact, I don't care about the order of A B and C. But I do care about

> the -sum-!

>

> For example, if you have the following formula; AxByCz, where x is the

> number of A's y is the number of B's, z is the number of C's...

>

> If k = x + y + z, I need to find all possible x, y and z values whose

> sum is equal to k.

>

> So, if k = 3, I could have:

> x y z

> 1 0 2

> 1 1 1

> 1 2 0

> 2 0 1

> etc, etc, etc.

>

> Sadly, I did not drink enough coffee today to see the quick way to do

> this either... any help appreciated!

>

> B

>
Well, there are an infinite number of solutions to this unless you put

some constraints on the values of x y and z, like insisting they are all

non-negative (from your example, perhaps you mean x to be positive and y

and z to be non-negative?). One way would be to just brute-force it:

$k=10;

for $x(0..$k){

for $y(0..$k){

for $z(0..$k){

print "x=$x, y=$y, z=$z, sum=$k\n" if $x+$y+$z==$k;

}

}

}

There might be a slighly more efficient or elegant way, but why waste

time on it when the computer can do it practically instantly anyway?

--

Bob Walton

Email:

http://bwalton.com/cgi-bin/emailbob.pl