Skip to content
FutureBlitz

    Install

    Import std.algo.combinatorics

    std.algo.combinatorics

    Permutations and Combinations: every order, or every choice, of an array's elements, made one at a time as a For ... In or an adapter asks, each a new array, in the order of the elements' positions, as Python's itertools gives them; and Factorial and Binomial, which count them. The elements are taken by position, so equal ones still make orders and choices of their own.

    std/algo/combinatorics.fb

    Types

    PermutationIterator class

    Public Class PermutationIterator<T> Implements Iterator<T[]>

    Gives every order of count elements of an array, from the first order by position.

    std/algo/combinatorics.fb, line 10

    CombinationIterator class

    Public Class CombinationIterator<T> Implements Iterator<T[]>

    Gives every choice of count elements of an array, each in the array's order, from the first elements on.

    std/algo/combinatorics.fb, line 81

    Functions

    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.

    std/algo/combinatorics.fb, line 139

    Permutations 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.

    std/algo/combinatorics.fb, line 145

    Combinations function

    @PanicsAtCaller Public Function Combinations<T>(items: T[], count: Int): CombinationIterator<T>

    Every choice of count of the array's elements, each in the array's order: Binomial(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.

    std/algo/combinatorics.fb, line 154

    Factorial function

    @PanicsAtCaller Public Function Factorial(n: Int): Long

    n!, the number of orders of n things, from 0! = 1 to 20!, the most a Long holds. Any other n panics.

    std/algo/combinatorics.fb, line 162

    Binomial function

    @PanicsAtCaller Public Function Binomial(n: Int, k: Int): Long

    The number of ways to choose k of n things, "n choose k": 0 for a k below 0 or above n. A negative n panics, and so does a count too large for a Long.

    std/algo/combinatorics.fb, line 174

    Report an issue with this page or with FutureBlitz on GitHub.