Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Obtaining terms in an expansion

by QM (Parson)
on Jan 07, 2006 at 17:10 UTC ( #521728=note: print w/replies, xml ) Need Help??


in reply to Re^2: Obtaining terms in an expansion
in thread Obtaining terms in an expansion

Completely irrelevant time waster:
#!/your/perl/here use strict; use warnings; { # closure for sub terms my @term_list = ('A'..'Z', 'a'..'z'); sub terms { my $N = shift; my $last = 2*$N-1; my @pairs; my $index = 0; my $globber = ''; while ( $index < $last ) { $globber .= '{' . $term_list[$index++] . ',' . $term_list[$index++] . '}'; } my $terms = join ' + ', glob($globber); return $terms; } } # end closure for sub terms foreach my $n (1..5) { my $terms = terms($n); print "N=$n: <", $terms, ">\n"; } exit; __OUTPUT__ N=1: <A + B> N=2: <AC + AD + BC + BD> N=3: <ACE + ACF + ADE + ADF + BCE + BCF + BDE + BDF> N=4: <ACEG + ACEH + ACFG + ACFH + ADEG + ADEH + ADFG + ADFH + BCEG + B +CEH + BCFG + BCFH + BDEG + BDEH + BDFG + BDFH> N=5: <ACEGI + ACEGJ + ACEHI + ACEHJ + ACFGI + ACFGJ + ACFHI + ACFHJ + +ADEGI + ADEGJ + ADEHI + ADEHJ + ADFGI + ADFGJ + ADFHI + ADFHJ + BCEGI + + BCEGJ + BCEHI + BCEHJ + BCFGI + BCFGJ + BCFHI + BCFHJ + BDEGI + BD +EGJ + BDEHI + BDEHJ + BDFGI + BDFGJ + BDFHI + BDFHJ>

-QM
--
Quantum Mechanics: The dreams stuff is made of

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://521728]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2021-05-11 14:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (117 votes). Check out past polls.

    Notices?