Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
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 about the Monastery: (6)
As of 2014-12-25 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls