Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: P6: Combinations Solution

by kvale (Monsignor)
on May 20, 2005 at 06:42 UTC ( [id://458859]=note: print w/replies, xml ) Need Help??


in reply to P6: Combinations Solution

What you are computing is the power set of a set of elements (minus the empty set), not combinations per se. Here is a p5 solution for comparison:
my @check = qw/ 1 2 3 4/; foreach my $index (0..2**@check-1) { my @combo; foreach my $pos (0..@check-1) { push @combo, $check[$pos] if ($index >> $pos) % 2; } print join " ", @combo, "\n"; }

-Mark

Replies are listed 'Best First'.
Re^2: P6: Combinations Solution
by eric256 (Parson) on May 20, 2005 at 06:58 UTC

    I thought combinations usualy meant all possible (groupings? subsets?) of one or more elements of the original set. "One or more elements selected from a set without regard to the order of selection." -- dictionary.com

    I'm no set theory expert and dictionary.com certainly isn't the be all end all source of mathematicaly truth. So what other definition of combinations do you have AND how would you implement it in perl6 ;)


    ___________
    Eric Hodges
      Sorry for the lack of explanation. Combinations has a mathematinal definition more specialized and distinct from the usual dictionary version. Combinations are all the subsets of a set of a given size. So for the set (1,2,3,4) the combination of subsets with 2 elements is ((1,2),(1,3),(1,4),(2,3),(2,4),(3,4). The number of cominations of 4 elements chosen 2 at a time is called "4 choose 2)" or sometimes C(4,2) and in this case is equal to 6.

      If one puts all the subsets generated from 4 choose 0, 4 choose 1, ..., 4 choose 4 into a set, that set of sets is called a power set of the original set.

      I would implement combinations in p5 and then use the mythical p5 to p6 converter :) Just joking, but I haven't dived into p6 yet.

      -Mark

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-24 08:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found