From qscgz@aol.com Tue Jan 5 15:46:27 CST 1999 Article: 228053 of sci.math Path: news.math.niu.edu!husk.cso.niu.edu!vixen.cso.uiuc.edu!logbridge.uoregon.edu!news-peer.gip.net!news.gsl.net!gip.net!cpk-news-hub1.bbnplanet.com!news.gtei.net!portc02.blue.aol.com!audrey01.news.aol.com!not-for-mail From: qscgz@aol.com (QSCGZ) Newsgroups: sci.math Subject: Re: efficient way to code ordering Lines: 38 NNTP-Posting-Host: ladder01.news.aol.com X-Admin: news@aol.com Date: 5 Jan 1999 14:57:10 GMT Organization: AOL Bertelsmann Online GmbH & Co. KG http://www.germany.aol.com References: <76q3kj$bk9$1@sparcserver.lrz-muenchen.de> Message-ID: <19990105095710.01576.00004974@ng36.aol.com> Xref: news.math.niu.edu sci.math:228053 Helmut Richter wrote: >To assign a number to an ordering, throw out the highest number, get >the order number, say X, of what remains, multiply by the length of >the ordering, and add where the highest number has to fit in (counting >from right if X even and from left if X odd). [ Example snipped ] >The rule that the positions are counted alternatingly from right and >from left is not necessary for the uniqueness of the numbering, but it >is very useful: so the permutation number n+1 is obtained from >permutation number n by swapping two adjacent elements. In particular, >the order number of a permutation is odd if and only if the >permutation itself is odd (that is: takes an odd number of swaps of >arbitrary elements to restore the standard ordering; or: has an odd >number of pairs of elements that are not in standard order). > >Note the symmetry: the circle is closed, and the reverse string of >permutation i has number i+-(n!/2). yes, I like it. So I wrote an implementation in BASIC : ' -------------c=code of the permutation p(1..n)--------------- C=0:FOR I=2 TO N Z=0:K=1:WHILE P(K)<>I:Z=Z-(P(K)