bal-sama / 摩天大楼
解决《纽约时报》摩天大楼谜题的小助手。
1.0.0-alpha1
2016-09-28 19:45 UTC
Requires
- najidev/permutation: ^1.0.0
Requires (Dev)
- phpunit/phpunit: 4.0.*
This package is auto-updated.
Last update: 2024-09-05 19:05:30 UTC
README
摩天大楼
一个PHP类,帮助您解决《纽约时报杂志》中的摩天大楼谜题。
用法
基础
$view = new View();
// There are four buildings per view, for a total of 24 purmutations.
$view->setBlocks(4);
// Only show permutations in which exactly three Skyscrapers are visible.
$view->setDesiredVisible(3);
// Only show permutuations where the fourth Skyscraper is of height 4
$view->addConstraint(4, "==", 4);
// Also, only show permutations where the second is greater than 1
$view->addConstraint(2, ">", 1);
// And the first is not 2
$view->addConstraint(1, "!=", 2);
// Get the solutions
$possibleSolutions = $view->getSolutions();
描述
视图是站在谜题板上某一行或列的末端所能看到的。实例化一个视图
$view = new View();
视图中的摩天大楼总数由 blocks() 方法设置。默认情况下,视图中有三个方块。纽约时报的谜题长度为4或5个方块。要更改方块数量
$view->setBlocks($number_of_blocks);
纽约时报的谜题提供了某些视图可见的摩天大楼数量。要为视图设置该数量,您可以使用 setDesiredVisible() 方法。默认值为3。要更改期望的可见数量
$view->setDesiredVisible($number_visible);
在解决谜题的过程中,您会遇到某些方块将包含特定高度(或以下或以上)的摩天大楼的情况。约束可以链式连接 - 也就是说,您可以在不影响先前定义的约束的情况下定义多个约束。为了使类意识到这些,您可以添加一个约束。addConstraint() 方法接受三个参数
- 位置:方块在视图中的位置(1是最接近的)。
- 操作符:建筑物与值的关系(可用操作符
- 大于 (">")
- 小于 ("<")
- 等于 ("==")
- 值:用于比较的值。
以下约束将结果限制在第三块中摩天大楼高度为三的谜题上
$view->setConstraint(3, "==", 3);
一旦您设置了方块、期望的可见性和任何约束,您可以使用以下方式获取结果
$view->getSolutions();