Ad
Code
Diff
  • function dividedByThree(int $number): bool
    {
        $abs = abs($number);
        if($abs < 10){
            return $abs == 3 || $abs == 6 || $abs == 9;
        }
        $sum = array_sum(str_split($abs,1));
        return dividedByThree($sum);
    }
    
    • function dividedByThree(int $number): bool
    • {
    • $i = 3;
    • do {
    • if (abs($number) === $i) {
    • return true;
    • }
    • $i += 3;
    • } while (abs($number) >= $i);
    • return false;
    • $abs = abs($number);
    • if($abs < 10){
    • return $abs == 3 || $abs == 6 || $abs == 9;
    • }
    • $sum = array_sum(str_split($abs,1));
    • return dividedByThree($sum);
    • }