Re: Combination of binary variables



"Nightfall" <chesbobba@xxxxxxxxx> wrote in message
news:1175203021.816435.48620@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Dear friends,
this is my problem: let's take an array of n binary variables. I need
an algorithm to write every possible combination of those variables.

If, say, n = 3, the algorithm should output:

000
001
010
100
011
110
101
111

I have to implement this algorithm in Mosel language (the language
used in Xpress-Optimizer), but this does't matter: can you help me
with just some "pseudo-code", please?

Why not just count up to 111 and display the binary value? I.E.

int Bits = 3;
for ( int i = 0; i < pow( 2, 3 ); ++i )
// output i as binary

Outputing a decimal value in some base is not difficult.


.



Relevant Pages

  • Combination of binary variables
    ... let's take an array of n binary variables. ... an algorithm to write every possible combination of those variables. ... I have to implement this algorithm in Mosel language (the language ...
    (comp.programming)
  • Re: Combination of binary variables
    ... let's take an array of n binary variables. ... an algorithm to write every possible combination of those variables. ... char buf; ... int main ...
    (comp.programming)
  • Re: regex question - trying to find ".mp3" in a SELECT box
    ... But `Array' is a Function object reference. ... Establish a new execution context using F's FormalParameterList, ... Since is not a primitive value, the exception should be thrown. ... | 5.2 Algorithm Conventions ...
    (comp.lang.javascript)
  • Re: Mergesort Vs Quicksort
    ... I might not have correctly remembered my algorithm of months ago ... for sorting records in an array using one auxilary of the ... on how things turn out from lower levels of recursion, ... whether the number of records in the array segment to be sorted is ...
    (comp.programming)
  • Re: Reference to derived type element by index?
    ... as a set of distinctively-named scalars. ... In another scope, the same common block ... would be a single array. ... algorithm and a specific application of the algorithm, ...
    (comp.lang.fortran)