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
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
8 Likes