creating all possible combinations problem
hi im trying to create a java program which basically takes all possible combinations (subtraction and addition) of 14 numbers, but I need some help.
right now im trying to get the 13 possible combinations of + and - into a list so I can "plug" them into the series of numbers.
but I can't figure out a systematic way to achieve all 2^13 combinations of + and -.
any suggestion or help?
[412 byte] By [
loopay_fa] at [2007-11-27 10:34:52]

Say you have 4 numbers (A,B,C,D) and 2 operators (+,-). The only thing you need to do is count from zero to ((numbers-1)^2)-1 in base 2 (the number of operators).
Example:
A0B0C0D
001
010
011
100
101
110
111
and substitute a all 0's for -, and all 1's for + (or the other way around).
> Say you have 4 numbers (A,B,C,D) and 2 operators
> (+,-). The only thing you need to do is count from
> zero to ((numbers-1)^2)-1 in base 2
Make that from 0 (inclusive) to 2^(numbers-1) (exclusive)
kind regards,
Jos
ps. I take it that -A-B-C-D isn't allowed?
JosAHa at 2007-7-28 18:31:39 >

Hey Jos, nice to see you around here again!
> Make that from 0 (inclusive) to 2^(numbers-1)
> (exclusive)
Err, yes, if you insist on explaining it more clearly...
; )
> kind regards,
>
> Jos
>
> ps. I take it that -A-B-C-D isn't allowed?
The OP didn't seem to be interested in that case. But s/he can probably figure out how to handle it now.
> Hey Jos, nice to see you around here again!
I hope it's safe now here ;-)
> > Make that from 0 (inclusive) to 2^(numbers-1) (exclusive)
>
> Err, yes, if you insist on explaining it more clearly...
> ; )
Your explanation was fine, your little formula was just dead wrong.
> >
> > ps. I take it that -A-B-C-D isn't allowed?
>
> The OP didn't seem to be interested in that case. But
> s/he can probably figure out how to handle it now.
But it doesn't allow for B-A+C+D etc. either, i.e. A will never be subtracted
from something else. I guess the OP has to decide what s/he wants.
kind regards,
Jos
JosAHa at 2007-7-28 18:31:39 >

> Your explanation was fine, your little formula was
> just dead wrong.
Cripes, I only see it now that I posted the 2 in the wrong place!
*blush*
; )
> > Your explanation was fine, your little formula was
> > just dead wrong.
>
> Cripes, I only see it now that I posted the 2 in the
> wrong place!
> *blush*
> ; )
Me thinks that if you have n operands you should count all combinations
of n bits, except for 0 which means -A-B-C-D and it introcduces the
unary minus which is not allowed I guess. All other bit combinations can
be arranged such that the leading term starts with a unary plus, e.g.
-A-B-C+D == D-A-B-C etc.
kind regards,
Jos
JosAHa at 2007-7-28 18:31:39 >
