tomazos has asked for the wisdom of the Perl Monks concerning the following question:
Suppose I have a list of peoples names:
my @people = ("Peter", "Paul", "Jane", "Mary", "Fred");
I want to arrange them into teams:
my @example_teams = (["Peter", "Mary"], ["Paul"], ["Jane", "Fred"]);
In fact, I want to get all possible teams:
my @all_teams = ( [["Peter"], ["Mary"], ["Paul"], ["Jane"], ["Fred"]], [["Peter", "Paul"], ["Mary"], ["Jane"], ["Fred"]], . . . [["Peter", "Mary", "Paul", "Jane", "Fred"]] );
But not by iterating over them and storing them in a table, because there isn't enough memory.
Instead I want a function that takes a scalar number and returns a given grouping and visa-versa:
lookupteam(\@people, \@example_team); # returns 42 constuctteam(\@people, 42); # returns [["Peter", "Mary"], ["Paul"], ["Jane", "Fred"]]
I understand this has something to do with algorithms for perumtations, combinatorics, stirling numbers of the second kind, etc, etc.
Can anyone give me some pointers on where to look, or what the algorithm is called? Or even write a quick version of lookupteam and constructteam?
Thanks, Andrew.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Permutation of groups
by Limbic~Region (Chancellor) on Nov 19, 2006 at 18:58 UTC | |
Re: Permutation of groups
by ww (Archbishop) on Nov 19, 2006 at 19:03 UTC | |
Re: Permutation of groups
by blokhead (Monsignor) on Nov 20, 2006 at 15:05 UTC | |
by Limbic~Region (Chancellor) on Nov 20, 2006 at 16:58 UTC | |
by tomazos (Deacon) on Nov 20, 2006 at 20:16 UTC | |
by Limbic~Region (Chancellor) on Nov 20, 2006 at 20:50 UTC | |
Re: Permutation of groups
by Limbic~Region (Chancellor) on Nov 21, 2006 at 01:11 UTC |
Back to
Seekers of Perl Wisdom