2
$\begingroup$

You want to print vectors with n elements, where:

  • the first element can have the values: e1.1, e1.2, e1.2;

  • the second element can assume the values: e2.1, e2.2, e2.3;

  • ...;

  • ...;

  • the nth element can assume the values: en.1, en.2, en.3.

I should print all possible vectors; eg:

{e1.1, e2.1, en.1 ...};

{e1.2, e2.1, en.1 ...};

etc. etc.

Someone could indicate an algorithm making use of while/for loop to print these vectors?

Thanks so much!

$\endgroup$
  • 1
    $\begingroup$ Those are not permutations. A permutation of a set S is a bijective function from S onto itself. What did you try? $\endgroup$ – quicksort Dec 27 '16 at 20:57
1
$\begingroup$

The idea is to think of your output as representing a number in a mixed base. The $i$th digit has base $b_i$, where $b_i$ is the number of options for the $i$th element. You can then print all possible vectors essentially by implementing a counter. I'll let you work out the details.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.