function main()
{
    include_once 'numbers.php';
    $numbers = listToArray($numberList);
    $digitCount = count($numbers[0]);
    $numberCount = count($numbers);
    $realSum = [];
    $startUnit = 0;
    /**
     * This use the elementary sum method from right to left.
     */
    for ($i = $digitCount - 1; $i >= 0; $i--) {
        $sum = 0;
        for ($j = 0; $j < $numberCount; $j++) {
            $sum += intval($numbers[$j][$i]);
        }
        $sumSplit = array_reverse(str_split(strval($sum)));
        for ($k = 0; $k < count($sumSplit); $k++) {
            // NOTE: This null coalesce (??) only works on PHP 7
            $realSum[$startUnit + $k] = $realSum[$startUnit + $k] ?? 0;
            // Get the sum by column
            $colSum = $realSum[$startUnit + $k] + intval($sumSplit[$k]);
            // Put remainder to the current result column
            $realSum[$startUnit + $k] = $colSum % 10;
            // If the column sum is >= 10, put the carry number to the next result column
            if ($colSum >= 10) {
                $realSum[$startUnit + $k + 1] = $realSum[$startUnit + $k + 1] ?? 0;
                // NOTE: This intdiv() is also only on PHP 7
                $realSum[$startUnit + $k + 1] += intdiv($colSum, 10);
            }
        }
        $startUnit++;
    }
    var_dump(implode(array_reverse($realSum)));
}
Beispiel #2
0
         $out[$c]['type'] = 'changed';
     }
     if (strnatcmp($waka['drafts'][$_REQUEST['u']]['dateImagesTouched'], $_REQUEST['d']) > 0) {
         $c = count($out);
         $out[$c]['html'] = renderItemImagesForm($waka['drafts'][$_REQUEST['u']], 'draft');
         $out[$c]['location'] = 'draft_images_form';
         $out[$c]['type'] = 'changed';
     }
     if (strnatcmp($waka['drafts'][$_REQUEST['u']]['dateFilesTouched'], $_REQUEST['d']) > 0) {
         $c = count($out);
         $out[$c]['html'] = renderItemFilesForm($waka['drafts'][$_REQUEST['u']], 'draft');
         $out[$c]['location'] = 'draft_files_form';
         $out[$c]['type'] = 'changed';
     }
 }
 $oldplist = listToArray($_REQUEST['p']);
 $postcount = count($waka['posts']);
 for ($p = 0; $p < $postcount; $p++) {
     for ($p2 = 0; $p2 < count($oldplist); $p2++) {
         if ($oldplist[$p2] == $waka['posts'][$p]['id']) {
             array_splice($oldplist, $p2, 1);
         }
     }
     if (strnatcmp($waka['posts'][$p]['dateCreated'], $_REQUEST['d']) > 0) {
         $c = count($out);
         $out[$c]['html'] = renderPost($waka['posts'][$p], $waka['users'], $user);
         $out[$c]['location'] = 'post_' . $waka['posts'][$p]['id'];
         $out[$c]['type'] = 'new';
     } else {
         if (strnatcmp($waka['posts'][$p]['dateContentTouched'], $_REQUEST['d']) > 0) {
             $c = count($out);