Algorithm for getting combinations ...

Jens Rehsack <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.sybase.devel
Message-ID <[email protected]>
Hi Peter,

I played a bit with glob vs. combine_nk from "The Art of Computer 
Programming" by Knuth, and received:

ernie:DBI-Test sno$ time perl -MData::Dumper -le 'my @l = (1 .. 20); my 
@x = map { [ grep { $_ != 0 } split(//,$_) ] } glob( join( "", map { 
"{0,$_}" } @l ) ); print scalar @x'
1048576

real	0m16.314s
user	0m12.443s
sys	0m3.861s
ernie:DBI-Test sno$ time perl -Mlib=lib -MData::Dumper -MDBI::Test::Conf 
-e 'my @l = (1 .. 20); my @x = map { 
DBI::Test::Conf::combine_nk(scalar(@l), $_); } (1 .. scalar @l); print 
scalar @x'
1048575
real	0m5.229s
user	0m4.997s
sys	0m0.226s

So iterating and mapping test variants from got combinations list
should be much faster using the Knuth algorithm. It doesn't matter
for less amount of possible combinations, but for larger amounts ...

Cheers
-- 
Jens Rehsack
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.