# PetscDTEnumPerm
Get a permutation of n integers from its encoding into the integers [0, n!) as a sequence of swaps. A permutation can be described by the operations that convert the lists [0, 1, ..., n-1] into the permutation,
by a sequence of swaps, where the ith step swaps whatever number is in ith position with a number that is in
some position j >= i.  This swap is encoded as the difference (j - i).  The difference d_i at step i is less than
(n - i).  This sequence of n-1 differences [d_0, ..., d_{n-2}] is encoded as the number
(n-1)! * d_0 + (n-2)! * d_1 + ... + 1! * d_{n-2}.


## Input Parameters

- ***n -*** a non-negative integer (see note about limits below)
- ***k -*** an integer in [0, n!)



## Output Parameters

- ***perm -*** the permuted list of the integers [0, ..., n-1]
- ***isOdd -*** if not NULL, returns whether the permutation used an even or odd number of swaps.



## Note
Limited to n such that n! can be represented by `PetscInt`, which is 12 if `PetscInt` is a signed 32-bit integer and 20 if `PetscInt` is a signed 64-bit integer.



## Level
beginner

## Location
<A HREF="PETSC_DOC_OUT_ROOT_PLACEHOLDER/include/petscdt.h.html#PetscDTEnumPerm">include/petscdt.h</A>


---
[Edit on GitLab](https://gitlab.com/petsc/petsc/-/edit/release/include/petscdt.h)


[Index of all DT routines](index.md)  
[Table of Contents for all manual pages](/docs/manualpages/index.md)  
[Index of all manual pages](/docs/manualpages/singleindex.md)  
