2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace DNW\Skills\Numerics;
|
2016-05-24 14:10:39 +02:00
|
|
|
|
|
|
|
class SquareMatrix extends Matrix
|
|
|
|
{
|
2022-07-05 16:21:06 +02:00
|
|
|
public function __construct(...$allValues)
|
2016-05-24 14:10:39 +02:00
|
|
|
{
|
2022-07-05 15:55:47 +02:00
|
|
|
$rows = (int) sqrt(count($allValues));
|
2016-05-24 14:10:39 +02:00
|
|
|
$cols = $rows;
|
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
$matrixData = [];
|
2016-05-24 14:10:39 +02:00
|
|
|
$allValuesIndex = 0;
|
|
|
|
|
|
|
|
for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
|
|
|
|
for ($currentColumn = 0; $currentColumn < $cols; $currentColumn++) {
|
|
|
|
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
parent::__construct($rows, $cols, $matrixData);
|
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|