Created
March 18, 2025 10:15
-
-
Save celyes/12989b322a1cb15111961aaedad8e5c6 to your computer and use it in GitHub Desktop.
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 characters
| <?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment