SparkeyG has asked for the wisdom of the Perl Monks concerning the following question:
It works as I want, I am just wondering if this could be done better or more efficently.
--SparkeyG
#!/usr/bin/perl my @list = (1 .. 5); my $take = 2; comb(\@list, $take, []); sub comb { my @items = @{ $_[0] }; my $group = $_[1]; my @list = @{ $_[2] }; unless ($group) { print "@list\n"; } else { my (@newitems,@newlist,$i); foreach $i (0 .. $#items) { @newlist = @list; push (@newlist, shift (@items)); @newitems = @items; comb([@newitems], $group - 1, [@newlist]); } } }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Printing combinations, code review request
by demerphq (Chancellor) on Apr 26, 2003 at 13:06 UTC | |
Re: Printing combinations, code review request
by integral (Hermit) on Apr 26, 2003 at 13:27 UTC | |
by demerphq (Chancellor) on Apr 26, 2003 at 15:16 UTC | |
by integral (Hermit) on Apr 26, 2003 at 15:42 UTC | |
Re: Printing combinations, code review request
by demerphq (Chancellor) on Apr 26, 2003 at 14:50 UTC | |
Re: Printing combinations, code review request
by terrencebrown (Acolyte) on Apr 27, 2003 at 19:26 UTC | |
by terrencebrown (Acolyte) on Apr 27, 2003 at 19:37 UTC | |
by SparkeyG (Curate) on Apr 28, 2003 at 00:32 UTC |