Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Combinatorics

by I0 (Priest)
on Aug 23, 2002 at 05:03 UTC ( #192266=note: print w/ replies, xml ) Need Help??


in reply to Combinatorics

use Data::Dumper; my @my_array = (1..7); my $my_sub_array_length = 4; print Dumper(combinations($my_sub_array_length, @my_array)); sub combinations { my($len,@a)=@_; return map{ my $c=$_<<1; [grep{($c>>=1)&1}@a]} &{sub{ my @ret = (); my $x; for($_=(1<<shift)-1; ($x=$_)<1<<$_[0]; $x&=~$x>>1,$x&=-$x,$_+=$x--,($x&=$_)?($_-=$x,$_+=$x/($ +x&-$x)):0 ){ push @ret,$_ } @ret; }}($len,0+@a); }


Comment on Re: Combinatorics
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2015-07-29 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (260 votes), past polls