Skip to content

Commit 84546e8

Browse files
Pol DellaieraPol Dellaiera
authored andcommitted
#6: Update the README file.
1 parent 932bfdf commit 84546e8

File tree

1 file changed

+84
-30
lines changed

1 file changed

+84
-30
lines changed

README.md

Lines changed: 84 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,88 @@
11
## PHPermutations
22
[![Build Status](https://travis-ci.org/drupol/phpermutations.svg?branch=master)](https://travis-ci.org/drupol/phpermutations) [![Code Coverage](https://scrutinizer-ci.com/g/drupol/phpermutations/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/drupol/phpermutations/?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/drupol/phpermutations/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/drupol/phpermutations/?branch=master) [![Dependency Status](https://www.versioneye.com/user/projects/5870ade140543803e80abb5b/badge.svg?style=flat-square)](https://www.versioneye.com/user/projects/5870ade140543803e80abb5b)
33

4-
PHP iterators and generators to generate combinations and permutations in an efficient way.
4+
PHP Iterators and Generators to generate combinations and permutations in an efficient way.
55

66
At first the library was created to only generate permutations and combinations.
7+
78
In the end, I added other Iterators and Generators like:
89
* Fibonacci numbers,
910
* Perfect numbers,
1011
* Prime numbers,
1112
* Product of numbers,
12-
* ... more to come.
13+
* Rotation of an array,
14+
* Cycling through an array,
15+
* Permutations,
16+
* Combinations,
17+
18+
## Introduction
19+
20+
I've always been fascinated by numbers and everything around them... in other words, mathematics.
21+
22+
The library has been written first for being used in [PHPartition](https://github.com/drupol/phpartition), then it has
23+
been extended here and there.
24+
25+
Its main use is for generating Permutations and Combinations without running out of memory, thanks to
26+
[PHP Generators](https://secure.php.net/manual/en/language.generators.overview.php) and
27+
and [Iterators](https://secure.php.net/manual/en/class.iterator.php).
28+
29+
The difference with other combinatorics library is that you can use an extra parameter 'length', that allows you to
30+
compute Permutations and Combinations of a particular size.
31+
The other notable difference is that your input arrays may contains any type of object (integers, arrays, strings or
32+
objects), the library will still continue to work without any trouble.
33+
34+
## Requirements
35+
36+
* PHP >= 5.6,
37+
* (optional) [PHPUnit](https://phpunit.de/) to run tests.
38+
39+
## How to use
40+
41+
Include this library in your project by doing:
42+
43+
`composer require drupol/phpermutations`
44+
45+
Let's say you want to find all the permutations of the list of number [1, 2, 3, 4, 5] having a length of 3:
46+
47+
```php
48+
// Create the object
49+
$permutations = new \drupol\phpermutations\Generators\Permutations([1,2,3,4,5], 3);
50+
51+
// Use a foreach loop.
52+
foreach ($permutations->generator() as $permutation) {// do stuff}
53+
54+
// Or get the whole array at once.
55+
$permutations->toArray();
56+
```
57+
58+
Most of the components always has the same arguments except for very few of them.
59+
60+
As the documentation per component is not written yet, I advise you to
61+
[check the tests](https://github.com/drupol/phpermutations/tree/master/tests/src) to see how to use them.
62+
63+
## Combinations
64+
65+
> In mathematics, a combination is a way of selecting items from a collection, such that (unlike permutations) the order
66+
> of selection does not matter.
67+
> -- [_Wikipedia_](https://en.wikipedia.org/wiki/Combination)
68+
69+
In one sentence: _When the order doesn't matter, it is a Combination._
70+
71+
## Examples
72+
73+
Let's say we have a group of fruits:
74+
75+
`$list = ['Apple', 'Pear', 'Banana', 'Orange']`
76+
77+
and we want to find the combinations of length: `3`, the result will be:
78+
79+
`['Apple', 'Pear', 'Banana']`
80+
81+
`['Apple', 'Pear', 'Orange']`
82+
83+
`['Apple', 'Banana', 'Orange']`
84+
85+
`['Pear', 'Banana', 'Orange']`
1386

1487
## Permutations
1588

@@ -76,35 +149,16 @@ and we want to find the permutations of length: `3`, the result will be:
76149

77150
`['Orange', 'Banana', 'Pear']`
78151

79-
## Combinations
80-
81-
> In mathematics, a combination is a way of selecting items from a collection, such that (unlike permutations) the order
82-
> of selection does not matter.
83-
> -- [_Wikipedia_](https://en.wikipedia.org/wiki/Combination)
84-
85-
In one sentence: _When the order doesn't matter, it is a Combination._
86-
87-
## Examples
88-
89-
Let's say we have a group of fruits
152+
The permutations of length 3 of the array [1, 2, 3, 4, 5] are, _please hold on tight_, the sum of all the permutations
153+
of each combinations having a length of 3 of that array.
90154

91-
`$list = ['Apple', 'Pear', 'Banana', 'Orange']`
155+
## Tests
92156

93-
and we want to find the combinations of length: `3`, the result will be:
157+
Each Generators and Iterators are tested using the same values as input. I try to be as much complete as possible with
158+
the [tests](https://github.com/drupol/phpermutations/tree/master/tests/fixtures).
159+
Every time the sources are modified, [Travis](https://travis-ci.org/drupol/phpermutations), the continuous integration
160+
service, tests the code against those tests, this way you are aware if the changes that you are introducing are valid.
94161

95-
`['Apple', 'Pear', 'Banana']`
96-
97-
`['Apple', 'Pear', 'Orange']`
98-
99-
`['Apple', 'Banana', 'Orange']`
162+
# Contributing
100163

101-
`['Pear', 'Banana', 'Orange']`
102-
103-
## Inspired by
104-
105-
* Many stackoverflow posts.
106-
107-
## Requirements
108-
109-
* PHP >= 5.6,
110-
* (optional) [PHPUnit](https://phpunit.de/) to run tests.
164+
Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)

0 commit comments

Comments
 (0)