josantonius/algorithm

此包已被废弃且不再维护。未建议替代包。

包含解决和显示数学序列的算法的类。

1.1.7 2022-06-01 22:54 UTC

This package is auto-updated.

Last update: 2022-07-14 16:58:05 UTC


README

Latest Stable Version License PSR2 PSR4 CodeCov

翻译西班牙语

包含解决和显示数学序列的算法的类。

要求

此类支持 PHP 版本 5.6 或更高版本,并兼容 HHVM 版本 3.0 或更高...

安装

安装此扩展的首选方式是通过 Composer

要安装 PHP 算法类,只需

composer require josantonius/algorithm

上述命令将仅安装必要的文件,如果您想 下载整个源代码,可以使用

composer require josantonius/algorithm --prefer-source

您也可以使用 Git 克隆完整的仓库

git clone https://github.com/josantonius/php-algorithm.git

或者 手动安装

下载 Algorithm.php:

wget https://raw.githubusercontent.com/josantonius/php-algorithm/master/src/Algorithm.php

可用方法

此类中的可用方法

打印 "观察并说" 序列

Algorithm::lookAndSay($lastSequence, $maxLines);
属性 描述 类型 必需 默认
$lastSequence 开始序列的初始值 int 1
$maxLines 要显示的最大行数 int 15

返回 (string) → 序列。

快速开始

要使用 Composer 使用此类

require __DIR__ . '/vendor/autoload.php';

use Josantonius\Algorithm\Algorithm;

如果您已手动安装,则使用它

require_once __DIR__ . '/Algorithm.php';

use Josantonius\Algorithm\Algorithm;

用法

此类使用的示例

echo Algorithm::lookAndSay();

/*
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
13211311123113112211
11131221133112132113212221
3113112221232112111312211312113211
1321132132111213122112311311222113111221131221
11131221131211131231121113112221121321132132211331222113112211
311311222113111231131112132112311321322112111312211312111322212311322113212221
*/
echo Algorithm::lookAndSay(22, 5);

/*
22
22
22
22
22
*/

测试

要运行 测试,您只需要 composer 并执行以下操作

git clone https://github.com/josantonius/php-algorithm.git
cd php-algorithm
composer install

使用 PHPUnit 运行单元测试

composer phpunit

使用 PSR2 代码标准测试使用 PHPCS

composer phpcs

运行 PHP Mess Detector 测试以检测代码风格中的不一致性

composer phpmd

运行所有之前的测试

composer tests

变更日志

每个版本的详细更改记录在 发行说明 中。

贡献

在提交贡献指南、发起拉取请求、开始讨论或报告问题之前,请务必阅读。

感谢所有为这个项目做出贡献的贡献者!❤️

赞助商

如果你觉得这个项目很有趣,你还可以成为我的赞助商! 😊

许可协议

本项目遵循MIT 许可协议

版权所有 © 2017-2022,Josantonius