New to Nutbox?

Sum

0 comments

drago18121996
68
2 days agoSteemit

declare(strict_types=1);

function sumOfMultiples(int $number, array $multiples): int{
$res = 1;
$setres = [];
foreach($multiples as $mult){
if($mult < 1 || $mult > $number) continue;
$i = 1;
while ($res = ($i * $mult) < $number){
$res = $i * $mult;
$setres[] = $res;
$i++;
}
}
$set = array_unique($setres);
return array_sum($set);
}

Comments

Sort byBest