承接 drupol/phpermutations 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

drupol/phpermutations

Composer 安装命令:

composer require drupol/phpermutations

包简介

Generators and iterators, permutations and combinations.

README 文档

README

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 :-)

drupol/phpermutations 适用场景与选型建议

drupol/phpermutations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 716.9k 次下载、GitHub Stars 达 80, 最近一次更新时间为 2016 年 12 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「product」 「math」 「numbers」 「iterators」 「fibonacci」 「combinations」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 drupol/phpermutations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 drupol/phpermutations 我们能提供哪些服务?
定制开发 / 二次开发

基于 drupol/phpermutations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 716.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 83
  • 点击次数: 27
  • 依赖项目数: 6
  • 推荐数: 1

GitHub 信息

  • Stars: 80
  • Watchers: 2
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-19