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

Hi,

I am wondering how to use the following subroutines found in the article: Permutations and combinations, and was wondering how I can change it slightly so that for each combination, there IS replacement. Right now, the code just does combinations without replacement. I am not sure how to do this in Perl. Any help would be greatly appreciated!

Jon Mustek

Replies are listed 'Best First'.
Re: Number Combinations With Replacement
by lemming (Priest) on Apr 18, 2002 at 19:30 UTC

    Wouldn't feeding the permute function with like arguments give what you want? print "[", join(", ", @$_), "]\n" for permute([1,2], [1,2]);has this for output:

    [1, 1] [1, 2] [2, 1] [2, 2]