Optimization efforts

This commit is contained in:
2024-02-15 09:08:01 +00:00
parent b966a930a4
commit 5bebd9310d
6 changed files with 12 additions and 14 deletions

View File

@ -8,18 +8,17 @@ class SquareMatrix extends Matrix
{
public function __construct(float|int ...$allValues)
{
$rows = (int)sqrt(count($allValues));
$cols = $rows;
$size = (int)sqrt(count($allValues));
$matrixData = [];
$allValuesIndex = 0;
for ($currentRow = 0; $currentRow < $rows; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $cols; $currentColumn++) {
for ($currentRow = 0; $currentRow < $size; $currentRow++) {
for ($currentColumn = 0; $currentColumn < $size; $currentColumn++) {
$matrixData[$currentRow][$currentColumn] = $allValues[$allValuesIndex++];
}
}
parent::__construct($rows, $cols, $matrixData);
parent::__construct($size, $size, $matrixData);
}
}