macfja / math
围绕数学的一组工具。
dev-master
2015-10-03 15:51 UTC
Suggests
- ext-bcmath: Install BCMath to improve and speed up factorial computation
- ext-gmp: Install GMP to improve and speed up factorial computation
This package is auto-updated.
Last update: 2024-09-17 00:36:15 UTC
README
一组围绕数学的类和函数。
里面有什么?
CombinationBuilder
一个用于创建组合的实用类。该类还提供阶乘计算。
示例和用法
Combination
获取5个数中的3个
print_r(CombinationBuilder::getCombination(5, 3));
将输出
Array
(
[1-2-3] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1-2-4] => Array
(
[0] => 1
[1] => 2
[2] => 4
)
[1-2-5] => Array
(
[0] => 1
[1] => 2
[2] => 5
)
[1-3-4] => Array
(
[0] => 1
[1] => 3
[2] => 4
)
[1-3-5] => Array
(
[0] => 1
[1] => 3
[2] => 5
)
[1-4-5] => Array
(
[0] => 1
[1] => 4
[2] => 5
)
[2-3-4] => Array
(
[0] => 2
[1] => 3
[2] => 4
)
[2-3-5] => Array
(
[0] => 2
[1] => 3
[2] => 5
)
[2-4-5] => Array
(
[0] => 2
[1] => 4
[2] => 5
)
[3-4-5] => Array
(
[0] => 3
[1] => 4
[2] => 5
)
)
或以更紧凑的方式
(1, 2, 3)
(1, 2, 4)
(1, 2, 5)
(1, 3, 4)
(1, 3, 5)
(1, 4, 5)
(2, 3, 4)
(2, 3, 5)
(2, 4, 5)
(3, 4, 5)
组合计数
获取可能的组合数量
print_r(CombinationBuilder::getCombinationCount(5, 3));
将输出
10
阶乘
获取5的阶乘(5!
)
print_r(CombinationBuilder::factorial(5));
将输出
120