blibio / combinatorics
Simple combination and permutation generators.
v1.1.0
2025-09-08 08:50 UTC
Requires
- php: ^8.3
- ext-gmp: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.87
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^2.1.22
- phpstan/phpstan-deprecation-rules: ^2.0.3
- phpstan/phpstan-phpunit: ^2.0.7
- phpstan/phpstan-strict-rules: ^2.0.6
- phpunit/phpunit: ^12.3.8
README
Simple PHP 8.3+ generators to create:
- combinations with or without repetition and
- permutations with or without repetition.
Installation
Install via Composer:
composer require blibio/combinatorics
Usage
To use the generators, simply create the kind of object you need, and iterate. E.g.:
<?php declare(strict_types=1); use Blibio\Combinatorics\Combinatorics; $elements = ['A', 'B', 'C', 'D']; $k = 3; // Using the boolean parameter: $it = Combinatorics::combinations($elements, $k, withRepetition: false); // or: // $it = Combinatorics::combinations($elements, $k, withRepetition: true); // $it = Combinatorics::permutations($elements, $k, withRepetition: false); // $it = Combinatorics::permutations($elements, $k, withRepetition: true); // Using the explicit method names: // $it = Combinatorics::combinationsWithoutRepetition($elements, $k); // $it = Combinatorics::combinationsWithRepetition($elements, $k); // $it = Combinatorics::permutationsWithoutRepetition($elements, $k); // $it = Combinatorics::permutationsWithRepetition($elements, $k); foreach ($it as $set) { // use $set }
Copyright and license
The blibio/combinatorics library is copyright © Stephan Six and licensed for use under the MIT License (MIT). Please see LICENSE for more information.