Sorting algorithms/Permutation sort: Difference between revisions

solved for maxscript
m (→‎{{header|REXX}}: removed STYLE from the PRE html tag.)
(solved for maxscript)
Line 834:
 
1 2 3 4 5 6</lang>
=={{header|MAXScript}}==
<lang MAXScript>fn inOrder arr =
(
if arr.count < 2 then return true
else
(
local i = 1
while i < arr.count do
(
if arr[i+1] < arr[i] do return false
i += 1
)
return true
)
)
 
fn permutations arr =
(
if arr.count <= 1 then return arr
else
(
for i = 1 to arr.count do
(
local rest = for r in 1 to arr.count where r != i collect arr[r]
local permRest = permutations rest
local new = join #(arr[i]) permRest
if inOrder new do return new
)
)
)</lang>
Output:
<lang MAXScript>
a = for i in 1 to 9 collect random 1 20
#(10, 20, 17, 15, 17, 15, 3, 11, 15)
permutations a
#(3, 10, 11, 15, 15, 15, 17, 17, 20)
</lang>
Warning: This algorithm is very inefficient and Max will crash very quickly with bigger arrays.
 
=={{header|Nimrod}}==
Anonymous user