Anonymous user
Sorting algorithms/Permutation sort: Difference between revisions
Sorting algorithms/Permutation sort (view source)
Revision as of 10:57, 18 September 2015
, 8 years agoAdded EchoLisp
m (Added the Sidef language) |
(Added EchoLisp) |
||
Line 472:
while (nextPermutation(flexList)) {}
}</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}}==
Not following the pseudocode, it seemed simpler to just test sorted at the bottom of a recursive permutation generator.
|