trivialmatters / square-matrix
A handy library that provides fluent OOP API for Square Matrix
2.0.0
2016-08-21 08:35 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^5.5
This package is not auto-updated.
Last update: 2025-01-15 00:28:45 UTC
README
Square Matrix
This is a PHP library that intends to provide a fluent API to make working with Square Matrix easier.
Requirements
- PHP 7 or greater
Versions
This project follows semver
Installation
- Add library in your composer.json:
$ composer require trivialmatters/square-matrix
Usage
<?php require_once __DIR__.'/vendor/autoload.php'; $data = <<<EOF 3 11 2 4 4 5 6 10 8 -12 EOF; // or create your own data provider $data = new Gkirtsou\DataProvider\StringDataProvider($data); $data->calculateRowsAndColumns(); /** * [ * [11, 4, 10] * [2, 5, 8] * [4, 6, -12] * ] */ $data->getColumns(); /** * [ * [11, 2, 4] * [4, 5, 6] * [10, 8, -12] * ] */ $data->getRows(); $squareMatrix = new Gkirtsou\SquareMatrix($data); // get numbers from first column (don't forget PHP starts counting from zero!) $squareMatrix->getNumbersByColumn(0); // get numbers from first row (don't forget PHP starts counting from zero!) $squareMatrix->getNumbersByRow(0); // diagonal difference $diagonalDifference = new \Gkirtsou\Diagonal\DiagonalDifference($squareMatrix); // find the diagonal difference $diagonalDifference->findDiagonalDifference(); // returns '15' // find primary diagonal (left to right): returns [11, 5, -12] $diagonalDifference->findDiagonal(\Gkirtsou\Diagonal\DiagonalDifference::PRIMARY_TYPE); // find secondary diagonal (right to left): returns [4, 5, 10] $diagonalDifference->findDiagonal(\Gkirtsou\Diagonal\DiagonalDifference::SECONDARY_TYPE);
Contributions
Want to contribute? Awesome! Please create an Issue in Issue Tracker to discuss about it, and create a Pull Request with your changes. Don't forget to write tests! :)
Installation
- Clone the repository
$ git clone git@github.com:trivialmatters/square-matrix.git
- Run Composer
$ composer install --prefer-dist -o -vvv
Tests
You can run tests using PHPUnit:
$ vendor/bin/phpunit -c phpunit.xml.dist tests