Import std.algo.combinatorics
Permutations
function
Public Function Permutations<T>(items: T[]): PermutationIterator<T>
Every order of the array's elements: n! of them, from the array's own order. The array is copied, so changing it doesn't change them.
Examples
Local orders: Int[][] = []
For order In Permutations([1, 2, 3])
orders.Add(order)
End For
Expect(orders.Count == 6)
Expect(orders[0] == [1, 2, 3] && orders[5] == [3, 2, 1])function
@PanicsAtCaller Public Function Permutations<T>(items: T[], count: Int): PermutationIterator<T>
Every order of count of the array's elements: n! / (n - count)! of them, none when count
is more than n, and one empty one for 0. The array is copied. A negative count panics.
Examples
Local pairs: String[][] = []
For pair In Permutations(["a", "b", "c"], 2)
pairs.Add(pair)
End For
Expect(pairs == [["a", "b"], ["a", "c"], ["b", "a"], ["b", "c"], ["c", "a"], ["c", "b"]])Report an issue with this page or with FutureBlitz on GitHub.