-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
853 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
include __DIR__ . '/../src/matrix.php'; | ||
|
||
use divengine\matrix; | ||
|
||
$m = new matrix([ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]); | ||
|
||
// echo $m->get(1, 1); | ||
echo $m->{1.1}; | ||
echo "\n"; | ||
|
||
// echo $m->{0.2}; | ||
echo $m->{.2}; | ||
echo "\n"; | ||
|
||
// echo $m->{2.2}; | ||
echo $m->{-1.2}; | ||
echo "\n"; | ||
|
||
for ($i = 0; $i < 3; $i++) | ||
for ($j = 0; $j < 3; $j++) | ||
echo $m->{$i + ($j / 10)} . " "; | ||
echo "\n"; | ||
|
||
for ($i = 0; $i < 3; $i++) | ||
for ($j = 0; $j < 3; $j++) | ||
echo $m->{($i + ($j / 10) + 1) * -1} . " "; | ||
echo "\n"; | ||
|
||
for ($i = 0; $i < 3; $i++) | ||
for ($j = 0; $j < 3; $j++) | ||
echo $m->{"$i.$j"} . " "; | ||
|
||
echo "\n"; | ||
|
||
$m->{0.0} = 10; | ||
echo $m; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
include __DIR__ . '/../src/matrix.php'; | ||
|
||
use divengine\matrix; | ||
|
||
// bidimensional array of random numbers | ||
$array = matrix::createArrayFromDims(5, 5, 0); | ||
|
||
// Create a new object matrix | ||
$m1 = new matrix($array); | ||
echo $m1->formatTXT(false); | ||
echo PHP_EOL; | ||
|
||
// Create a new matrix using the static method create | ||
$m2 = matrix::create($array); | ||
echo $m2->formatTXT(false); | ||
echo PHP_EOL; | ||
|
||
// Create an matrix from dimensions | ||
$m3 = matrix::dimension(5, 5, 0); | ||
echo $m3->formatTXT(false); | ||
echo PHP_EOL; | ||
|
||
// Create an matrix from a string | ||
$m4 = matrix::fromJSONFile(__DIR__.'/data/matrix.json'); | ||
echo $m4->formatTXT(false); | ||
echo PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
include __DIR__ . '/../src/matrix.php'; | ||
|
||
use divengine\matrix; | ||
|
||
$F_AMOUNT = fn($r, $c, matrix $m) => $m->{$r + .1} * $m->{$r +.2}; | ||
$F_TOTAL = fn($r, $c, matrix $m) => array_sum($m->vertical($c, 1, $m->rows - 1)); | ||
$F_AVG = fn($r, $c, matrix $m) => $F_TOTAL($r, $c, $m) / ($m->rows - 1); | ||
|
||
class ProductsTable extends matrix | ||
{ | ||
public function __construct(array $products) | ||
{ | ||
global $F_AMOUNT, $F_AVG, $F_TOTAL; | ||
|
||
$data = [["Name", "Price", "Qty", "Total"]]; | ||
foreach ($products as $product) | ||
{ | ||
$data[] = [$product->name, $product->price, $product->quantity, $F_AMOUNT]; | ||
} | ||
|
||
$data[] = ["Total", $F_AVG, $F_TOTAL, $F_TOTAL]; | ||
|
||
parent::__construct($data); | ||
} | ||
} | ||
|
||
echo new ProductsTable([ | ||
(object) ["name" => "Apple", "price" => 1.5, "quantity" => 10], | ||
(object) ["name" => "Banana", "price" => 2.5, "quantity" => 5], | ||
(object) ["name" => "Orange", "price" => 3.5, "quantity" => 3], | ||
(object) ["name" => "Kiwi", "price" => 4.5, "quantity" => 1], | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[ | ||
[1,2,3], | ||
[4,5,6], | ||
[7,8,9] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
include __DIR__ . '/../src/matrix.php'; | ||
|
||
use divengine\matrix; | ||
|
||
$m = new matrix([ | ||
[1, 2, 3], | ||
[4, 5, 6], | ||
[7, 8, 9] | ||
]); | ||
|
||
$m->insertAfterRow(1, [10, 11, 12]); | ||
|
||
echo $m; | ||
echo "\n"; | ||
|
||
$m->insertBeforeRow(1, [13, 14, 15]); | ||
|
||
echo $m; | ||
echo "\n"; | ||
|
||
$m->insertAfterColumn(1, 0); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->insertBeforeColumn(1, 0); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->removeColumn(1); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->removeRow(2); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->removeColumn(2); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->addColumn(5); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->removeColumnRange(1, 3); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->addColumn(6); | ||
$m->addRow([2, 2]); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->removeRowRange(1, 3); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->addColumn(7); | ||
$m->addRow([3, 3, 3]); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->fillRange(1, 1, 2, 2, 0); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->insertAfterColumn(1, [1, 2, 3]); | ||
echo $m; | ||
echo "\n"; | ||
|
||
$m->insertBeforeColumn(1, [4, 5, 6]); | ||
echo $m; | ||
echo "\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
include __DIR__ . '/../src/matrix.php'; | ||
|
||
use divengine\matrix; | ||
|
||
class MathTable extends matrix | ||
{ | ||
public function __construct($number, $size, $operation, $operator) | ||
{ | ||
$data = []; | ||
for ($i = 1; $i <= $size; $i++) | ||
{ | ||
$data[] = [$number, $operator, $i, "=", $operation]; | ||
} | ||
|
||
parent::__construct($data); | ||
} | ||
} | ||
|
||
class MultiplicationTable extends MathTable | ||
{ | ||
public function __construct($number = 1, $size = 10) | ||
{ | ||
parent::__construct($number, $size, fn ($r, $c, $m) => $m->get($r, 0) * $m->get($r, 2), "x"); | ||
} | ||
} | ||
|
||
class AdditionTable extends MathTable | ||
{ | ||
public function __construct($number = 1, $size = 10) | ||
{ | ||
parent::__construct($number, $size, fn ($r, $c, $m) => $m->get($r, 0) + $m->get($r, 2), "+"); | ||
} | ||
} | ||
|
||
for ($i = 1; $i <= 10; $i++) | ||
{ | ||
echo new MultiplicationTable($i); | ||
echo PHP_EOL; | ||
} | ||
|
||
echo PHP_EOL; | ||
|
||
for ($i = 1; $i <= 10; $i++) | ||
{ | ||
echo new AdditionTable($i); | ||
echo PHP_EOL; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
http_response_code(404); | ||
echo "Page not found"; | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
echo "About"; | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
echo "Admin"; | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
echo "Home"; | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
$url = $_SERVER['REQUEST_URI'] ?? ""; | ||
$moment = date("Y-m-d H:i:s"); | ||
|
||
// show in console log | ||
echo "<script>console.log('{$moment} - {$url}');</script>"; | ||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
return function () | ||
{ | ||
echo "Login"; | ||
return true; | ||
}; |
Oops, something went wrong.