Permutations: Difference between revisions

Content added Content deleted
Line 3,295: Line 3,295:


=={{header|PHP}}==
=={{header|PHP}}==
A full non-recursive algorithm generating permutation in reverse lexicographical mode.
Full non-recursive algorithm generating permutation in reversed lexicographical order.
Taken from here: [https://habrahabr.ru/post/275331/]. It's a little bit modified algorythm of Narayana Pandit [https://en.wikipedia.org/wiki/Narayana_Pandit]. It reveres a string and works until a and b are no equal. It searches
From here: [https://habrahabr.ru/post/275331/]
a new permutation directly (first internal cycle) as we do it on a sheet of paper. You can use English alphabet instead of digits.

<lang php>
<lang php>
$b="0123456";
$b="012345";
$a=strrev($b);
$a=strrev($b);
print_r($a);
print "\n";

while ($a !=$b) {
while ($a !=$b) {
$i=1;
$i=1;
Line 3,321: Line 3,326:


}</lang>
}</lang>

=={{header|Perl}}==
=={{header|Perl}}==
There are many modules that can do permutations, or it can be fairly easily done by hand with an example below. In performance order for simple permutation of 10 scalars, a sampling of some solutions:
There are many modules that can do permutations, or it can be fairly easily done by hand with an example below. In performance order for simple permutation of 10 scalars, a sampling of some solutions: