Expand Minimize

Array.permute<'T> Function (F#)

Returns an array with all elements permuted according to the specified permutation.

Namespace/Module Path: Microsoft.FSharp.Collections.Array

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array.permute : (int -> int) -> 'T [] -> 'T []

// Usage:
Array.permute indexMap array

indexMap

Type: int -> int

The function that maps input indices to output indices.

array

Type: 'T []

The input array.

The permuted array.

This function is named Permute in compiled assemblies. If accessing the function from a language other than F#, or through reflection, use this name.

The following code illustrates the use of Array.permute.

let printPermutation n array1 =
    let length = Array.length array1
    if (n > 0 && n < length) then
        Array.permute (fun index -> (index + n) % length) array1
    else
        array1
    |> printfn "%A" 
let array1 = [| 1 .. 5 |]
// There are 5 valid permutations of array1, with n from 0 to 4. 
for n in 0 .. 4 do
    printPermutation n array1 

Output

[|1; 2; 3; 4; 5|]
[|5; 1; 2; 3; 4|]
[|4; 5; 1; 2; 3|]
[|3; 4; 5; 1; 2|]
[|2; 3; 4; 5; 1|]

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft