Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
22
Task/Combinations/Perl5i/combinations.perl5i
Normal file
22
Task/Combinations/Perl5i/combinations.perl5i
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
use perl5i::2;
|
||||
|
||||
# ----------------------------------------
|
||||
# generate combinations of length $n consisting of characters
|
||||
# from the sorted set @set, using each character once in a
|
||||
# combination, with sorted strings in sorted order.
|
||||
#
|
||||
# Returns a list of array references, each containing one combination.
|
||||
#
|
||||
func combine($n, @set) {
|
||||
return unless @set;
|
||||
return map { [ $_ ] } @set if $n == 1;
|
||||
|
||||
my ($head) = shift @set;
|
||||
my @result = combine( $n-1, @set );
|
||||
for my $subarray ( @result ) {
|
||||
$subarray->unshift( $head );
|
||||
}
|
||||
return ( @result, combine( $n, @set ) );
|
||||
}
|
||||
|
||||
say @$_ for combine( 3, ('a'..'e') );
|
||||
Loading…
Add table
Add a link
Reference in a new issue