kevinsimard/combinatorics

Mathematical algorithms concerning the study of finite or countable discrete structures.

v1.0.5 2016-04-07 01:25 UTC

This package is not auto-updated.

Last update: 2024-05-16 13:17:02 UTC


README

Build Status

Usage

You may add new elements to the list by using the add method:

$instance = new Combinatorics(["foo", "bar"]);

$instance->add("baz");
$instance->add("qux");

// ["foo", "bar", "baz", "qux"]

You may also want to reset the list of elements by calling the reset method:

$instance = new Combinatorics(["foo", "bar"]);

$instance->reset();

// []

Permutations

$elements = ["foo", "bar", "baz"];

$instance = new Combinatorics($elements);
foreach ($instance->permutations() as $value) {
    ...
}

// OR

foreach (Combinatorics::permutations($elements) as $value) {
    ...
}

// [
//     ["foo", "bar", "baz"],
//     ["bar", "foo", "baz"],
//     ["bar", "baz", "foo"],
//     ["foo", "baz", "bar"],
//     ["baz", "foo", "bar"],
//     ["baz", "bar", "foo"]
// ]

Structure

├── src
│   └── Combinatorics.php
├── tests
│   └── CombinatoricsTest.php
├── .editorconfig
├── .gitattributes
├── .gitignore
├── .travis.yml
├── LICENSE.md
├── README.md
├── composer.json
├── composer.lock
└── phpunit.xml

License

This package is open-sourced software licensed under the MIT license.