All Projects → drupol → Phpermutations

drupol / Phpermutations

Licence: mit
Generate Permutations and Combinations in an efficient way.

Projects that are alternatives of or similar to Phpermutations

Papogen
Use Sass/CSS + Pug + Node.js to generate beautiful static website.
Stars: ✭ 37 (-33.93%)
Mutual labels:  generator
Brazilian Utils
Utils library for specific Brazilian businesses
Stars: ✭ 1,023 (+1726.79%)
Mutual labels:  generator
Bitcoinaddress
Bitcoin Wallet Address Generator
Stars: ✭ 52 (-7.14%)
Mutual labels:  generator
Ultimate Page Builder
📦 Ultimate Page Builder for WordPress
Stars: ✭ 39 (-30.36%)
Mutual labels:  generator
Hoshi
First-class views for Ruby.
Stars: ✭ 41 (-26.79%)
Mutual labels:  generator
Gwt Api Generator
Generator for creating GWT JSInterop clients from Polymer Web Components
Stars: ✭ 49 (-12.5%)
Mutual labels:  generator
Blog
About math, programming and procedural generation
Stars: ✭ 37 (-33.93%)
Mutual labels:  mathematics
Pycm
Multi-class confusion matrix library in Python
Stars: ✭ 1,076 (+1821.43%)
Mutual labels:  mathematics
Randomdatagenerator
This is a configurable generator to create random data like Lorum Ipsum Text, Words, Text Patterns, First/Last Names, MAC-Addresses, IP-Addresses, Guids and DateTime.
Stars: ✭ 45 (-19.64%)
Mutual labels:  generator
Rings
Rings: efficient JVM library for polynomial rings
Stars: ✭ 50 (-10.71%)
Mutual labels:  mathematics
Math Advanced Data Structures And Algorithms
Math, Advanced Data Structures & Algorithms - Please check before use
Stars: ✭ 40 (-28.57%)
Mutual labels:  mathematics
Ncform
🍻 ncform, a very nice configuration generation way to develop forms ( vue, json-schema, form, generator )
Stars: ✭ 1,009 (+1701.79%)
Mutual labels:  generator
Agda
Agda formalisation of the Introduction to Homotopy Type Theory
Stars: ✭ 50 (-10.71%)
Mutual labels:  mathematics
Math books
📚 Математичный список полезных книг
Stars: ✭ 38 (-32.14%)
Mutual labels:  mathematics
Geeksforgeeks Dsa 2
This repository contains all the assignments and practice questions solved during the Data Structures and Algorithms course in C++ taught by the Geeks For Geeks team.
Stars: ✭ 53 (-5.36%)
Mutual labels:  mathematics
Chasm
A CHaracter Aware Splitting Method for producing password candidates.
Stars: ✭ 37 (-33.93%)
Mutual labels:  generator
Latex Examples
Examples for the usage of LaTeX
Stars: ✭ 1,032 (+1742.86%)
Mutual labels:  mathematics
Laravel Graphql
GraphQL implementation with power of Laravel
Stars: ✭ 56 (+0%)
Mutual labels:  generator
Mish
Official Repsoitory for "Mish: A Self Regularized Non-Monotonic Neural Activation Function" [BMVC 2020]
Stars: ✭ 1,072 (+1814.29%)
Mutual labels:  mathematics
Go Adorable
Adorable Avatars from Go
Stars: ✭ 50 (-10.71%)
Mutual labels:  generator

Latest Stable Version GitHub stars Total Downloads GitHub Workflow Status Scrutinizer code quality Code Coverage License Donate!

PHPermutations

PHP Iterators and Generators to generate combinations and permutations in an efficient way.

At first the library was created to only generate permutations and combinations.

In the end, I added other Iterators and Generators like:

  • Fibonacci numbers,
  • Perfect numbers,
  • Prime numbers,
  • Product of numbers,
  • Rotation of an array,
  • Cycling through an array,
  • Permutations,
  • Combinations,

Introduction

I've always been fascinated by numbers and everything around them... in other words, mathematics.

The library has been written first for being used in PHPartition, then it has been extended here and there.

Its main use is for generating Permutations and Combinations without running out of memory, thanks to PHP Generators and and Iterators.

The difference with other combinatorics library is that you can use an extra parameter 'length', that allows you to compute Permutations and Combinations of a particular size. The other notable difference is that your input arrays may contains any type of object (integers, arrays, strings or objects), the library will still continue to work without any trouble.

Requirements

  • PHP >= 7.1.3,

How to use

Include this library in your project by doing:

composer require drupol/phpermutations

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:

// Create the object
$permutations = new \drupol\phpermutations\Generators\Permutations([1,2,3,4,5], 3);

// Use a foreach loop.
foreach ($permutations->generator() as $permutation) {// do stuff}

// Or get the whole array at once.
$permutations->toArray();

Most of the components always has the same arguments except for very few of them.

As the documentation per component is not written yet, I advise you to check the tests to see how to use them.

Combinations

In mathematics, a combination is a way of selecting items from a collection, such that (unlike permutations) the order of selection does not matter. -- Wikipedia

In one sentence: When the order doesn't matter, it is a Combination.

Examples

Let's say we have a group of fruits:

$list = ['Apple', 'Pear', 'Banana', 'Orange']

and we want to find the combinations of length: 3, the result will be:

['Apple', 'Pear', 'Banana']

['Apple', 'Pear', 'Orange']

['Apple', 'Banana', 'Orange']

['Pear', 'Banana', 'Orange']

Permutations

In mathematics, the notion of permutation relates to the act of arranging all the members of a set into some sequence or order, or if the set is already ordered, rearranging (reordering) its elements, a process called permuting. These differ from combinations, which are selections of some members of a set where order is disregarded. -- Wikipedia

In one sentence: When the order does matter, it is a Permutation.

Examples

Let's say we have a group of fruits

['Apple', 'Pear', 'Banana', 'Orange']

and we want to find the permutations of length: 3, the result will be:

['Apple', 'Pear', 'Banana']

['Pear', 'Apple', 'Banana']

['Apple', 'Banana', 'Pear']

['Banana', 'Apple', 'Pear']

['Pear', 'Banana', 'Apple']

['Banana', 'Pear', 'Apple']

['Apple', 'Pear', 'Orange']

['Pear', 'Apple', 'Orange']

['Apple', 'Orange', 'Pear']

['Orange', 'Apple', 'Pear']

['Pear', 'Orange', 'Apple']

['Orange', 'Pear', 'Apple']

['Apple', 'Banana', 'Orange']

['Banana', 'Apple', 'Orange']

['Apple', 'Orange', 'Banana']

['Orange', 'Apple', 'Banana']

['Banana', 'Orange', 'Apple']

['Orange', 'Banana', 'Apple']

['Pear', 'Banana', 'Orange']

['Banana', 'Pear', 'Orange']

['Pear', 'Orange', 'Banana']

['Orange', 'Pear', 'Banana']

['Banana', 'Orange', 'Pear']

['Orange', 'Banana', 'Pear']

The permutations of length 3 of the array [1, 2, 3, 4, 5] are, please hold on tight, the sum of all the permutations of each combinations having a length of 3 of that array.

Tests

Each Generators and Iterators are tested using the same values as input. I try to be as much complete as possible with the tests. Every time the sources are modified, Github, the continuous integration service, tests the code against those tests, this way you are aware if the changes that you are introducing are valid.

Contributing

Feel free to contribute to this library by sending Github pull requests. I'm quite reactive :-)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].