more useful options PerlMonks

### Comment on

 Need Help??
I would call this a special case of a ranking algorithm for combinations. An "unordered pair" as you have is simply a "subset of size 2" (or "combination of size 2"). A ranking algorithm is a 1-to-1 mapping from a set of N combinatorial objects to the integers {1...N}, with the additional property that it preserves some sort of "ordering" among the combinatorial objects.

In this case, your ranking algorithm preserves a form of lexicographic ordering. When you write the pairs as (M,N) with M>N, then you have that rank(M,N)<rank(R,S) if and only if (M,N) appears before (R,S) in lexicographic order. You may not actually use this property, but you got it for free. ;)

Look at the ranking algorithm I gave in Re: Sampling from Combination Space (for general combinations):

```sub rank {
my @comb = sort { \$a <=> \$b } @_;
sum map { binomial( \$comb[\$_]-1, \$_+1 ) } 0 .. \$#comb;
}
For combinations of size 2, ours both compute the same thing:
```  binomial(X,2)+binomial(Y,1) = X(X-1)/2 + Y
I got the algorithm from a PDF draft version of a textbook that may never get published (which would be a shame). That PDF is not available online anymore, but if you are curious, I can send you the copy I have archived (hopefully that's kosher). I would be surprised if these kinds of things don't also show up somewhere in Knuth TAoCP volume 4 (if it's out yet, that is), where it deals with the related topics of combinatorial generation.

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

• Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
• Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
• Read Where should I post X? if you're not absolutely sure you're posting in the right place.
• Posts may use any of the Perl Monks Approved HTML tags:
a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
• You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
 For: Use: & & < < > > [ [ ] ]
• Link using PerlMonks shortcuts! What shortcuts can I use for linking?

Create A New User
Chatterbox?
 [ambrus]: what kind of restaurant? [LanX]: with different specialized employees in different rooms [LanX]: communication overhead calls for sensible management [ambrus]: "different specialized employees in different rooms" => so, there's a cleaner guy who cleans up the vomit from the bathroom every morning? [erix]: makes me think of MMM too (mythical man month): "adding more people to a project makes it slower" [erix]: that should be "to an already-too-late- project" I think [ambrus]: oh yes, we have a pretty good example of that when they reorganized the grill place in the restaurant nearby. [ambrus]: it now has two more people working there, and they're serving slower and more expensive.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2017-09-22 13:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
During the recent solar eclipse, I:

Results (264 votes). Check out past polls.

Notices?