codingtests/solutions/other/sum44.php
2024-07-23 09:13:29 +00:00

24 lines
508 B
PHP

<?php
//12857 multiplied by 7 gives 90099, and the sum of the digits of 90099 is indeed 27, not 44. Keep trying!
function sumDigits($number) {
$sum = 0;
// converting number to string to access digits easily
$numberStr = (string)$number;
for ($i = 0; $i < strlen($numberStr); $i++) {
$digit = (int)$numberStr[$i];
$sum += $digit;
}
return $sum;
}
$i = 0;
while(true) {
$i++;
$var = $i*7;
if(sumDigits($var) == 44)
{
die("Found $i");
}
}