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.

Revisions

  1. celyes created this gist Mar 18, 2025.
    34 changes: 34 additions & 0 deletions task-1.php
    Original 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);