Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Multiple Combinatorics

by brx (Pilgrim)
on Apr 15, 2012 at 17:38 UTC ( #965182=note: print w/replies, xml ) Need Help??

in reply to Multiple Combinatorics

my @set1=(0..7); my @set2=(6..12); my @comb; { local $"=","; @comb = glob"{@set1}-{@set1}-{@set2}-{@set2}-{@set2}"' } print join "\n",@comb;

Then you can grep {...} the result to exclude some results. Of course, this is not very good with big sets or a lot of combinations (time and memory).

Update: I probably post the worst solution beacause you don't want to duplicate elements from set1 and set2. It's possible to "grep" the result to avoid duplicate but it is not beautiful/effective... Anyway, this usage of glob must be known, so I don't delete my contribution :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://965182]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2017-08-21 02:07 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (317 votes). Check out past polls.