Sorting algorithms/Permutation sort: Difference between revisions
Content added Content deleted
m (Added the Sidef language) |
(Added EchoLisp) |
||
Line 472: | Line 472: | ||
while (nextPermutation(flexList)) {} |
while (nextPermutation(flexList)) {} |
||
}</lang> |
}</lang> |
||
=={{header|EchoLisp}}== |
|||
<lang scheme> |
|||
;; This efficient sort method uses the list library for permutations |
|||
(lib 'list) |
|||
(define (in-order L) |
|||
(cond |
|||
((empty? L) #t) |
|||
((empty? (rest L)) #t) |
|||
(else (and ( < (first L) (second L)) (in-order (rest L)))))) |
|||
(define L (shuffle (iota 6))) |
|||
→ (1 5 4 2 0 3) |
|||
(for ((p (in-permutations (length L )))) |
|||
#:when (in-order (list-permute L p)) |
|||
(writeln (list-permute L p)) #:break #t) |
|||
→ (0 1 2 3 4 5) |
|||
</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |
||
Not following the pseudocode, it seemed simpler to just test sorted at the bottom of a recursive permutation generator. |
Not following the pseudocode, it seemed simpler to just test sorted at the bottom of a recursive permutation generator. |