-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8fabc1a
commit 28b61ae
Showing
1 changed file
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# Mathematics | ||
PHP Mathematics Library for easier calculation of Base Converts, Factorials, Permutation and Combination. | ||
|
||
## Installation | ||
You can install the package via composer: | ||
|
||
```bash | ||
composer require graphita/mathematics | ||
``` | ||
|
||
## Usage | ||
|
||
### Base Convert | ||
|
||
```php | ||
use Graphita\Mathematics\BaseConvert; | ||
|
||
// Convert a Number from Base 10 to Base 2 | ||
$result = BaseConvert::convert(6)->to(2)->getResult(); // 110 | ||
$resultArray = BaseConvert::convert(6)->to(2)->getResultArray(); // [1,1,0] | ||
|
||
// Convert a Number from Base 8 to Base 10 | ||
$result = BaseConvert::convert(20, 8)->to(10)->getResult(); // 16 | ||
|
||
// Convert a Number from Base 16 with Source Characters Map to Base 10 | ||
$result = BaseConvert::convert('FF', 16, '0123456789ABCDEF')->to(10)->getResult(); // 255 | ||
|
||
// Convert a Number from Base 10 to Base 16 with Destination Characters Map | ||
$result = BaseConvert::convert(255)->to(16, '0123456789ABCDEF')->getResult(); // FF | ||
|
||
// Convert a Number from Base 16 with Source Characters Map to Base 10 with Destination Characters Map | ||
$result = BaseConvert::convert('FF', 16, '0123456789ABCDEF')->to(10, 'ZYXWVUTSRQ')->getResult(); // XUU | ||
``` | ||
|
||
### Factorial | ||
|
||
```php | ||
use Graphita\Mathematics\Factorial; | ||
|
||
// Factrorial 3 : 3x2x1 | ||
$result = (new Factorial(3))->calculate(); // 6 | ||
|
||
// Factrorial 4 : 4x3x2x1 | ||
$result = (new Factorial(4))->calculate(); // 24 | ||
``` | ||
|
||
### Permutation | ||
|
||
```php | ||
use Graphita\Mathematics\Permutation; | ||
|
||
// Permutation two Character without Repetitions | ||
$permutation = new Permutation(); | ||
$permutation->setItems(['a', 'b']); | ||
$permutation->setSelection(2); | ||
$permutation->calculate(); | ||
$result = $permutation->getPossibilities(); // [ ['a', 'b'], ['b','a'] ] | ||
$count = $permutation->countPossibilities(); // 2 | ||
|
||
// Permutation two Character with Repetitions | ||
$permutation = new Permutation(); | ||
$permutation->setItems(['a', 'b']); | ||
$permutation->setSelection(2); | ||
$permutation->setRepetitions(true); | ||
$permutation->calculate(); | ||
$result = $permutation->getPossibilities(); // [ ['a', 'a'], ['a', 'b'], ['b','a'], ['b','b'] ] | ||
$count = $permutation->countPossibilities(); // 4 | ||
``` | ||
|
||
### Combination | ||
|
||
```php | ||
use Graphita\Mathematics\Combination; | ||
|
||
// Combination two Character without Repetitions | ||
$combination = new Combination(); | ||
$combination->setItems(['a', 'b']); | ||
$combination->setSelection(2); | ||
$combination->calculate(); | ||
$result = $combination->getPossibilities(); // [ ['a', 'b'] ] | ||
$count = $combination->countPossibilities(); // 1 | ||
|
||
// Combination two Character with Repetitions | ||
$combination = new Combination(); | ||
$combination->setItems(['a', 'b']); | ||
$combination->setSelection(2); | ||
$combination->setRepetitions(true); | ||
$combination->calculate(); | ||
$result = $combination->getPossibilities(); // [ ['a', 'a'], ['a', 'b'], ['b','b'] ] | ||
$count = $combination->countPossibilities(); // 3 | ||
``` | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE) for more information. | ||
|