Created
March 18, 2025 10:15
-
-
Save celyes/12989b322a1cb15111961aaedad8e5c6 to your computer and use it in GitHub Desktop.
Revisions
-
celyes created this gist
Mar 18, 2025 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ <?php function generateTable(int $rows, int $cols): array { $table = []; for ($i = 0; $i < $rows; $i++) { $row = []; for ($j = 0; $j < $cols; $j++) { $row[] = mt_rand() / mt_getrandmax(); } $table[] = $row; } return $table; } function computeCumSums(array $table): array { $cumTable = []; foreach ($table as $row) { $cumRow = []; $sum = 0; foreach ($row as $value) { $sum += $value; $cumRow[] = $sum; } $cumTable[] = $cumRow; } return $cumTable; } $table = generateTable(10, 52); $sums = computeCumSums($table); print_r($sums);