Compartir a través de


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

Parameters

  • indexMap
    Type: int -> int

    The function that maps input indices to output indices.

  • array
    Type: 'T[]

    The input array.

Return Value

The permuted array.

Remarks

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

Example

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|]

Platforms

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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Collections.Array Module (F#)

Microsoft.FSharp.Collections Namespace (F#)