Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Permutation of groups

by Limbic~Region (Chancellor)
on Nov 19, 2006 at 18:58 UTC ( [id://584966]=note: print w/replies, xml ) Need Help??


in reply to Permutation of groups

tomazos,
I believe what you are looking for is combinations not permutations. This is because the team ('Sarah', 'John', 'Ashley') is the same any which way you order the members. There are a couple ways of doing your rank/unrank scheme.

The first is to use binomial rankings as seen here. This approach is a bit cumbersome because it gives unique ranks for teams of a specific size only. This is fine as long as you pay attention to the size and adjust accordingly. For instance, you would need to specify the size of the team and the rank to retrieve the group:

A B C D Size 4 = ABCD rank 1 Size 3 = ABC ABD ACD BCD rank 1 .. 4 Size 2 = AB AC AD BC BD CD rank 1 .. 6 Size 1 = A B C D rank 1 .. 4

The second is to look at all the possible combinations and count in binary. This is the technique I used here (C code). Basically, the idea is to assign each element in the complete list a value and then for each combination to add them up. For instance:

A = 2^0 = 1 B = 2^1 = 2 C = 2^2 = 4 D = 2^3 = 8 A C D = 1 + 4 + 8 = 13
It should be pretty clear how to convert 13 back into powers of 2 and then get the original set back.

If you need fully working code let me know.

Cheers - L~R

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-25 12:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found