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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Combinations with variable length
by davido (Cardinal) on May 10, 2021 at 22:07 UTC | |
|
Re: Combinations with variable length
by LanX (Saint) on May 10, 2021 at 21:43 UTC | |
|
Re: Combinations with variable length
by tybalt89 (Monsignor) on May 10, 2021 at 21:30 UTC | |
|
Re: Combinations with variable length
by jo37 (Curate) on May 11, 2021 at 18:47 UTC | |
|
Re: Combinations with variable length
by ikegami (Patriarch) on May 12, 2021 at 15:55 UTC | |
|
Re: Combinations with variable length
by Anonymous Monk on May 10, 2021 at 22:14 UTC |