https://github.com/basemax/yourcombinationsphp
An efficient combinatorics library for PHP 8 to generate and get the list of all Permutations and Combinations with the ability to enable or disable repetition. (utilizing generators)
https://github.com/basemax/yourcombinationsphp
algorithm algorithms combinatoric combinatoric-functions combinatorics combinatorics-library generator generator-function generator-php generators generators-php permutation permutation-algorithms permutations php php-generator php-generators
Last synced: 4 days ago
JSON representation
An efficient combinatorics library for PHP 8 to generate and get the list of all Permutations and Combinations with the ability to enable or disable repetition. (utilizing generators)
- Host: GitHub
- URL: https://github.com/basemax/yourcombinationsphp
- Owner: BaseMax
- License: gpl-3.0
- Created: 2022-10-05T21:07:02.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-10-26T05:21:46.000Z (over 3 years ago)
- Last Synced: 2025-10-25T11:57:36.242Z (6 months ago)
- Topics: algorithm, algorithms, combinatoric, combinatoric-functions, combinatorics, combinatorics-library, generator, generator-function, generator-php, generators, generators-php, permutation, permutation-algorithms, permutations, php, php-generator, php-generators
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Your Combinations PHP
An efficient combinatorics library for PHP 8 to generate and get the list of all **Permutations** and **Combinations** with the ability to enable or disable repetition. (utilizing generators)
## Functions
- [PowerSet](#powerset)
- [Permutation with repetition](#permutation-with-repetition)
- [Permutation without repetition](#permutation-without-repetition)
- [Combinations with repetition](#combinations-with-repetition)
- [Combinations without repetition](#combinations-without-repetition)
## Usage
### PowerSet
```php
$your_combinations = new YourCombinations([1, 2, 3]);
print_r([...$your_combinations->powerSet()]);
// [
// [], [ 1 ],
// [ 2 ], [ 1, 2 ],
// [ 3 ], [ 1, 3 ],
// [ 2, 3 ], [ 1, 2, 3 ]
// ]
```
### Permutation with repetition
```php
$your_combinations = new YourCombinations([1, 2, 3]);
$your_combinations->Permutations(4, true);
// [ 1, 1, 1, 1 ]
// [ 1, 1, 1, 2 ]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]
// [ 3, 1, 2, 3 ]
// [ 3, 1, 3, 1 ]
// [ 3, 1, 3, 2 ]
// [ 3, 1, 3, 3 ]
// [ 3, 2, 1, 1 ]
// [ 3, 2, 1, 2 ]
// [ 3, 2, 1, 3 ]
// [ 3, 2, 2, 1 ]
// [ 3, 2, 2, 2 ]
// [ 3, 2, 2, 3 ]
// [ 3, 2, 3, 1 ]
// [ 3, 2, 3, 2 ]
// [ 3, 2, 3, 3 ]
// [ 3, 3, 1, 1 ]
// [ 3, 3, 1, 2 ]
// [ 3, 3, 1, 3 ]
// [ 3, 3, 2, 1 ]
// [ 3, 3, 2, 2 ]
// [ 3, 3, 2, 3 ]
// [ 3, 3, 3, 1 ]
// [ 3, 3, 3, 2 ]
// [ 3, 3, 3, 3 ]
```
### Permutation without repetition
```php
$your_combinations = new YourCombinations([1, 2, 3]);
$your_combinations->Permutations(2, false);
// [ 1, 2 ]
// [ 1, 3 ]
// [ 2, 1 ]
// [ 2, 3 ]
// [ 3, 1 ]
// [ 3, 2 ]
```
### Combinations with repetition
```php
$your_combinations = new YourCombinations([1, 2, 3]);
$your_combinations->Combinations(4, true);
// [ 1, 1, 1, 1 ]
// [ 1, 1, 1, 2 ]
// [ 1, 1, 1, 3 ]
// [ 1, 1, 2, 2 ]
// [ 1, 1, 2, 3 ]
// [ 1, 1, 3, 3 ]
// [ 1, 2, 2, 2 ]
// [ 1, 2, 2, 3 ]
// [ 1, 2, 3, 3 ]
// [ 1, 3, 3, 3 ]
// [ 2, 2, 2, 2 ]
// [ 2, 2, 2, 3 ]
// [ 2, 2, 3, 3 ]
// [ 2, 3, 3, 3 ]
// [ 3, 3, 3, 3 ]
```
### Combinations without repetition
```php
$your_combinations = new YourCombinations([1, 2, 3]);
$your_combinations->Combinations(2, false);
// [ 1, 2 ]
// [ 1, 3 ]
// [ 2, 3 ]
```
© Copyright, 2022 Max Base