View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Greg Wilson[_3_] Greg Wilson[_3_] is offline
external usenet poster
 
Posts: 35
Default Count combinations

As I understood Myrna, the nearly 14 million combinations
are the total possible for 6 elements from a list of 49.
(See the worksheet function Combin). This is not the
limited set that sum to 150.

You can obtain the number of combinations of 6 values that
sum to 150 using nested For/Next loops (i.e. brute force
as you put it). As you are aware, this would normally
take a very long time. However, in this case, since the
numbers 1 to 49 are in ascending order, you can include
code that aborts each loop once the sum exceeds 150 since
there would no longer be any point in continuing (because
the sum can only get bigger). This should drastically
reduce the time, I would think, but will still likely be
quite long.

The code to abort the inner loop is simple but a bit
tricky for the remainder. I'm pretty sure I've got it
figured out however. If your're interested, I could give
it a whirl. My guess is that the number will be in excess
of 100,000 !!!

Regards,
Greg

-----Original Message-----
From a set of integers from 1 to 49,
take 6 unique integers,
that if we sum them up, this sum is equal to 150.

Conditions:
1. The set numbers are integers from 1 to 49
2. subset size is 6
3. sum of the selected subset numbers is 150

My questions:
A. How many sets (combinations) of 6 unique numbers exist

that their sum
is 150?
B. Do you know of a function that can calculate that

quantity
of combinations, for different values of conditions

(1), (2), & (3)?

Thank you,

.