# Get all Permutations of Array?

**URL:** <https://discourse.julialang.org/t/get-all-permutations-of-array/48578>\
**Category:** New to Julia\
**Created:** [October 18, 2020, 9:55am UTC](https://discourse.julialang.org/t/get-all-permutations-of-array/48578 "2020-10-18T09:55:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 18, 2020, 9:55am UTC](https://discourse.julialang.org/t/get-all-permutations-of-array/48578/1 "2020-10-18T09:55:42Z")

</div>

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](https://en.wikibooks.org/wiki/Julia_for_MATLAB_Users/Core_Language/Mathematics#perms_All_possible_permutations)

```julia
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

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 18, 2020, 9:57am UTC](https://discourse.julialang.org/t/get-all-permutations-of-array/48578/2 "2020-10-18T09:57:23Z")

</div>

> [@Ahmed\_Salih](#):
>
> `permutations`

> [@Getting all possible combination of vector with all possible order](https://discourse.julialang.org/t/getting-all-possible-combination-of-vector-with-all-possible-order/879):
>
> 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

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 18, 2020, 9:59am UTC](https://discourse.julialang.org/t/get-all-permutations-of-array/48578/3 "2020-10-18T09:59:01Z")

</div>

Found it!

> **[GitHub - JuliaMath/Combinatorics.jl: A combinatorics library for Julia](https://github.com/JuliaMath/Combinatorics.jl)**
>
> A combinatorics library for Julia. Contribute to JuliaMath/Combinatorics.jl development by creating an account on GitHub.

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
