Get all Permutations of Array?

Hi

I found some old Julia code which states that this used to work:
https://en.wikibooks.org/wiki/Julia_for_MATLAB_Users/Core_Language/Mathematics#perms_All_possible_permutations

julia> perms(a) = reverse(collect(permutations(a)))
perms (generic function with 1 method)

julia> perms([2,4,6])
6-element Array{Array{Int64,1},1}:
 [6, 4, 2]
 [6, 2, 4]
 [4, 6, 2]
 [4, 2, 6]
 [2, 6, 4]
 [2, 4, 6]

But I cannot get this to work in Julia 1.5. Could anyone help out?

Kind regards

Old thread stating similar code which does not work either anymore.

Kind regards

Found it!

This package, and not “Permutations.jl” has the relevant function.

EDIT: A more performant solution is looking at “nthperm” and “nthperm!” in the same package. Especially if you want to generate it for arrays greater than 1x6

8 Likes