Sorting algorithms/Pancake sort: Difference between revisions

Content added Content deleted
(Added solution for Action!)
Line 2,932: Line 2,932:
{1,2,3,4,5,6,7,8,9,10}
{1,2,3,4,5,6,7,8,9,10}
</pre>
</pre>

=={{header|Picat}}==
<lang Picat>go =>
Nums = [6,7,8,9,2,5,3,4,1],
println(Nums),
Sorted = pancake_sort(Nums),
println(Sorted),
nl.

pancake_sort(L) = L =>
T = L.len,
while (T > 1)
Ix = argmax(L[1..T]),
if Ix == 1 then
L := L[1..T].reverse ++ L.slice(T+1),
T := T-1
else
L := L[1..Ix].reverse ++ L.slice(Ix+1)
end
end.

% Get the index of the (first) maximal value in L
argmax(L) = MaxIx =>
Max = max(L),
MaxIx = [I : I in 1..L.length, L[I] == Max].first.</lang>

{{out}}
<pre>[6,7,8,9,2,5,3,4,1]
[1,2,3,4,5,6,7,8,9]</pre>


=={{header|PicoLisp}}==
=={{header|PicoLisp}}==