Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Re: Permutation of groups by Limbic~Region
in thread Permutation of groups by tomazos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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 17:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found