mozy contest: problem 3 PHP solution

Nicholas Leippe nick at leippe.com
Mon Nov 6 10:03:28 MST 2006


The third problem was to simply add up all the digits in the input.

<?

$sum = 0;
while ($line = fgets(STDIN)) {
        $matches = array();
        preg_match_all("([0-9])", $line, $matches);
        $sum += array_sum($matches[0]);

}

echo "$sum\n";



More information about the PLUG mailing list