in reply to Algorithm to convert combinations to bitstring
let n be the 0 based length of your set (for ABCDE n = 4) let x be the 0 based position of the first element (for 'CD' x = 2) let y be the 0 based position of the second element (for 'CD' y = 3) The position in the outputed combination would be: [n(n+1)-x(x+1)]/2 + y-x so for 'CD': [4(4+1) - 2(2+1)]/2 + 3 - 2 ==> [20 - 6]/2 + 1 = 8 (solution is not 0 based)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Algorithm to convert combinations to bitstring
by Limbic~Region (Chancellor) on Oct 18, 2006 at 17:55 UTC | |
by doowah2004 (Monk) on Oct 18, 2006 at 19:36 UTC |