Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Combinatorics

by DamnDirtyApe (Curate)
on Aug 22, 2002 at 05:30 UTC ( [id://191934]=note: print w/replies, xml ) Need Help??


in reply to Combinatorics

#! /usr/bin/perl -w use strict ; use Data::Dumper ; $|++ ; my @my_array = (0, 1, 2, 3) ; my $my_sub_array_length = 2 ; my @subsets = () ; for ( 3 .. 2 ** @my_array ) { my @digits = reverse split // => sprintf "%b", $_ ; if ( ( grep { $_ } @digits ) == $my_sub_array_length ) { my @sub_arr = grep { $digits[$_] } @my_array ; push @subsets, \@sub_arr ; } } print Dumper( \@subsets ) ; exit ; __END__

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 23:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found