Skip to content

Instantly share code, notes, and snippets.

@celyes
Created March 18, 2025 10:15
Show Gist options
  • Save celyes/12989b322a1cb15111961aaedad8e5c6 to your computer and use it in GitHub Desktop.
Save celyes/12989b322a1cb15111961aaedad8e5c6 to your computer and use it in GitHub Desktop.
<?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