[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: math question



PureBytes Links

Trading Reference Links

> I need to see certain combinations for a portfolio analysis
> project I'm working on.  I guess this involves a bunch of nested
> loops?  For example, to obtain subsets of 4 unique numbers, I need
> 4 nested loops and then check if a, b, c, and d, hold unique
> numbers. 

You just need to use 4 nested loops and make sure you DON'T choose 
any repeated numbers.  In pseudo-code it would look like this:

for w = 1 to 20
  for x = w+1 to 20
    for y = x+1 to 20
      for z = y+1 to 20
        print w, x, y, z

BTW Mark's formula (20.C.4) is read as "20 choose 4."  You calculate 
"X choose Y" as X! / (Y! * (X-Y)!), where X! is "X factorial."

Gary