Permutations: Difference between revisions
Content added Content deleted
(→{{header|AppleScript}}: Simplified closures, updated library functions) |
|||
Line 3,294: | Line 3,294: | ||
00:00:01.328</pre> |
00:00:01.328</pre> |
||
=={{header|PHP}}== |
|||
A full non-recursive algorithm generating permutation in reverse lexicographical mode. |
|||
From here: [https://habrahabr.ru/post/275331/] |
|||
<lang php> |
|||
$b="0123456"; |
|||
$a=strrev($b); |
|||
while ($a !=$b) { |
|||
$i=1; |
|||
while($a[$i] > $a[$i-1]) { |
|||
$i++; |
|||
} |
|||
$j=0; |
|||
while($a[$j] < $a[$i]) { |
|||
$j++; |
|||
} |
|||
$c=$a[$j]; |
|||
$a[$j]=$a[$i]; |
|||
$a[$i]=$c; |
|||
$x=strrev(substr($a, 0, $i)); |
|||
$y=substr($a, $i); |
|||
$a=$x.$y; |
|||
print '<br/>'; |
|||
}</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: |