Sorting algorithms/Permutation sort: Difference between revisions
Content added Content deleted
(add task to aarch64 assembly raspberry pi) |
(Added Wren) |
||
Line 2,235: | Line 2,235: | ||
{{out}} |
{{out}} |
||
<pre><'dwj','ejw','hhp','oao','ock','oqh','pmf'></pre> |
<pre><'dwj','ejw','hhp','oao','ock','oqh','pmf'></pre> |
||
=={{header|Wren}}== |
|||
{{trans|Go}} |
|||
{{libheader|Wren-sort}} |
|||
<lang ecmascript>import "/sort" for Sort |
|||
var a = [170, 45, 75, -90, -802, 24, 2, 66] |
|||
// recursive permutation generator |
|||
var recurse |
|||
recurse = Fn.new { |last| |
|||
if (last <= 0) return Sort.isSorted(a) |
|||
for (i in 0..last) { |
|||
var t = a[i] |
|||
a[i] = a[last] |
|||
a[last] = t |
|||
System.write("") // guard against VM recursion bug |
|||
if (recurse.call(last - 1)) return true |
|||
t = a[i] |
|||
a[i] = a[last] |
|||
a[last] = t |
|||
} |
|||
return false |
|||
} |
|||
System.print("Unsorted: %(a)") |
|||
var count = a.count |
|||
if (count > 1 && !recurse.call(count-1)) Fiber.abort("Sorted permutation not found!") |
|||
System.print("Sorted : %(a)") |
|||
System.print("Unsorted: %(a)") |
|||
var count = a.count |
|||
if (count > 1 && !recurse.call(count-1)) Fiber.abort("Sorted permutation not found!") |
|||
System.print("Sorted : %(a)")</lang> |
|||
{{out}} |
|||
<pre> |
|||
Unsorted: [170, 45, 75, -90, -802, 24, 2, 66] |
|||
Sorted : [-802, -90, 2, 24, 45, 66, 75, 170] |
|||
</pre> |
|||
=={{header|zkl}}== |
=={{header|zkl}}== |