http://www.perlmonks.org?node_id=11132353

TryingTheBest has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone.

I am working with a combination script that is giving me problems.

This is as below:

I have two static numbers: 1 and 2.

And also I have a non-static number that represent the size of the combinations.

Example: 3 (combinations of 3 characters).

I need to perform ALL combinations using the static number, but considering the non-static number.

In the example with "3" as non-static number, this will be:

1 1 1
1 1 2
1 2 1
1 2 2
2 1 1
2 1 2
2 2 1
2 2 2

( I think I don't forget any combination :P )

Someone can help me with the code, please? I tried using use Algorithm::Combinatorics qw( combinations ); but I could not solve it.

Thanks all!