Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Combinatorics

by I0 (Priest)
on Aug 23, 2002 at 05:03 UTC ( [id://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); }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-19 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found