Hi
I found some old Julia code which states that this used to work:
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
Ahmed_Salih:
permutations
I know that there is combination function whthin package 'Combinatorics’
which gives me all possible combination without regarding order of elements
x = combinations([1,2,3], 3)
# which gives this
collect(x) => [1,2,3]
# but I couldn't find function for getting this.
=> [[1,2,3], [2,1,3], [3,1,2], [3,2,1]]
I looked up “Combinatorics” and “Iterators” Packages, but couldn’t find function I need.
thanks for your time.
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
7 Likes