Mathematics desk | ||
---|---|---|
< January 8 | << Dec | January | Feb >> | January 10 > |
Welcome to the Wikipedia Mathematics Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
I refer to this section of the Permutation article:
BEGIN
For every number () this following algorithm generates the corresponding permutation of the initial sequence :
function permutation(k, s) { var int factorial:= 1; for j = 2 to length(s) { factorial := factorial* (j-1); swap( s[j - ((k / factorial) mod j)], s[j]); } return s; }
Notation
END
The algorithm is supposed to generate every different permutation of the integers 1 to n, but when I coded it there were repetitions - could someone else check this, please?
Also, the bit following "Notation" seems to be written very clumsily, omitting the generally-understood word "remainder".81.153.219.51 16:42, 9 January 2007 (UTC)
Yes, I was using successive sequences - when I reset to 123...n order before each use, everything worked fine, thanks. With this apparently not working I searched for alternative algorithms - this one seems by far the shortest. It's a pity there is no attribution of source.
Re. the text, yes I'll change it - I hadn't fully appreciated how things were here.
With a dynamic IP address it may not look as if I'm the same person as before, but I am.81.153.220.80 18:27, 10 January 2007 (UTC)
can someone explain what a recurrence relation is and how it works in simple terms, giving an example. i have read the wiki and dont understand it. thanks —The preceding unsigned comment was added by 86.136.40.7 (talk) 23:00, 9 January 2007 (UTC).