11# Combinatorics
22
3- [ ![ TravisCI] ( )] ( )
4- [ ![ Maintainability] ( )] ( )
5- [ ![ Test Coverage] ( )] ( )
3+ [ ![ TravisCI] ( https://travis-ci.org/phpexpertsinc/Combinatorics.svg?branch=master )] ( https://travis-ci.org/phpexpertsinc/Combinatorics )
4+ [ ![ Maintainability] ( https://api.codeclimate.com/v1/badges/cb607de8292ed5b208ae/maintainability )] ( https://codeclimate.com/github/phpexpertsinc/Combinatorics/maintainability )
5+ [ ![ Test Coverage] ( https://api.codeclimate.com/v1/badges/cb607de8292ed5b208ae/test_coverage )] ( https://codeclimate.com/github/phpexpertsinc/Combinatorics/test_coverage )
66
77Combinatorics is a PHP Experts, Inc., Project meant for the ease of access of Combinatorics algorithms.
88
99See https://en.wikipedia.org/wiki/Combinatorics
1010
11+ ### Memory Consumption
12+ Storing thousands of possibilities can be extremely memory intensive.
13+
14+ However, this project utilizes PHP Generators and uses only a few kilobytes to calculate and output
15+ millions of potential combinations (See the ** Benchmarks** section below).
16+
17+ ### Generating All Possible Combinations
18+
19+ What are all the possibilities of A, B, C and D? More than you might think! 64.
20+ Add two more letters and you've got 1,956 possibilities.
21+
22+ How many different parking spot orderings can 8 cars occupy on any given day?
23+ Find out in the ** Usage** section below!
24+
1125## Installation
1226
1327Via Composer
@@ -17,9 +31,20 @@ composer require phpexperts/combinatorics
1731```
1832
1933## Usage
34+ ``` php
35+ $generator = new CombinationsGenerator();
36+
37+ foreach ($generator->generate($styles) as $combination) {
38+ // If you can do what you need to do with the combinations here, without immediately storing
39+ // them into an array, then your memory usage will never exceed the amount needed store one
40+ // combination.
41+ }
42+ ```
2043
44+ You can see real-world usage of this project in the test suite of the
45+ ** Console Painter project** ] ( https://github.com/PHPExpertsInc/ConsolePainter ) .
2146
22- # Use cases
47+ ## Use cases
2348
2449## Testing
2550
@@ -33,9 +58,94 @@ To actually see what's going on -and- run the stress tests, run
3358phpunit --debug
3459```
3560
36- Note: It takes over 4 minutes on an Intel i7 to run all of the stress tests.
61+ Note: It takes over 5 minutes on an Intel i7 to run all of the stress tests.
62+
63+ ## Benchmarks
64+
65+ ``` php
66+ Level 1: Generating combinations for A
67+ [
68+ Number of possibilities => 2
69+ Time (ms) => 0.051975250244141
70+ Time (s) => 5.1975250244141E-5
71+ Memory consumed => 0
72+ Peak Memory (Diff) => 0
73+ ]
74+ Level 2: Generating combinations for A, B
75+ [
76+ Number of possibilities => 4
77+ Time (ms) => 0.047922134399414
78+ Time (s) => 4.7922134399414E-5
79+ Memory consumed => 0
80+ Peak Memory (Diff) => 0
81+ ]
82+ Level 3: Generating combinations for A, B, C
83+ [
84+ Number of possibilities => 15
85+ Time (ms) => 0.22578239440918
86+ Time (s) => 0.00022578239440918
87+ Memory consumed => 0
88+ Peak Memory (Diff) => 0
89+ ]
90+ Level 4: Generating combinations for A, B, C, D
91+ [
92+ Number of possibilities => 64
93+ Time (ms) => 1.0910034179688
94+ Time (s) => 0.0010910034179688
95+ Memory consumed => 0
96+ Peak Memory (Diff) => 0
97+ ]
98+ Level 5: Generating combinations for A, B, C, D, E
99+ [
100+ Number of possibilities => 325
101+ Time (ms) => 6.5748691558838
102+ Time (s) => 0.0065748691558838
103+ Memory consumed => 0
104+ Peak Memory (Diff) => 0
105+ ]
106+ Level 6: Generating combinations for A, B, C, D, E, F
107+ [
108+ Number of possibilities => 1956
109+ Time (ms) => 47.721147537231
110+ Time (s) => 0.047721147537231
111+ Memory consumed => 0
112+ Peak Memory (Diff) => 0
113+ ]
114+ Level 7: Generating combinations for A, B, C, D, E, F, G
115+ [
116+ Number of possibilities => 13699
117+ Time (ms) => 395.29585838318
118+ Time (s) => 0.39529585838318
119+ Memory consumed => 0
120+ Peak Memory (Diff) => 0
121+ ]
122+ Level 8: Generating combinations for A, B, C, D, E, F, G, H
123+ [
124+ Number of possibilities => 109600
125+ Time (ms) => 3834.4430923462
126+ Time (s) => 3.8344430923462
127+ Memory consumed => 0
128+ Peak Memory (Diff) => 0
129+ ]
130+ Level 9: Generating combinations for A, B, C, D, E, F, G, H, I
131+ [
132+ Number of possibilities => 986409
133+ Time (ms) => 37884.353876114
134+ Time (s) => 37.884353876114
135+ Memory consumed => 320
136+ Peak Memory (Diff) => 0
137+ ]
138+ Level 10: Generating combinations for A, B, C, D, E, F, G, H, I, J
139+ [
140+ Number of possibilities => 9864100
141+ Time (ms) => 422606.03785515
142+ Time (s) => 422.60603785515
143+ Memory consumed => 0
144+ Peak Memory (Diff) => 0
145+ ]
146+ ```
37147
38- # Contributors
148+ ## Contributors
39149
40150[ Theodore R. Smith] ( https://www.phpexperts.pro/] ) < theodore@phpexperts.pro >
41151GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690
0 commit comments