Problem 42405. Divisible by 3

Pursuant to the first problem in this series, this one involves checking for divisibility by 3.

Write a function to determine if a number is divisible by 3. This can be checked by at least two different methods:

  1. Sum the digits in the number. If the resulting sum is divisible by 3, then so is the original number. This routine can be applied recursively until the resulting sum is a single digit.
  2. From the wikipedia reference page: "Subtract the quantity of the digits 2, 5, and 8 in the number from the quantity of the digits 1, 4, and 7 in the number." If the resulting sum (absolute value) is a multiple of 3, then so is the original number.

Previous problem: divisible by 2. Next problem: divisible by 4.

Solution Stats

34.91% Correct | 65.09% Incorrect
Last Solution submitted on Jun 22, 2020

Problem Comments

Solution Comments